# RecordId

The RecordId class represents a SurrealDB record identifier consisting of a table name and an ID value.

A `RecordId` uniquely identifies a record in SurrealDB. It consists of a table name and an ID value. The ID can be a `long`, `String`, `UUID`, or a composite key using `Array` or `Object`. See the [SurrealQL record ID documentation](/docs/reference/query-language/language-primitives/data-types/record-ids.md) for details on how record identifiers work in SurrealDB.

**Source:** [surrealdb.java](https://github.com/surrealdb/surrealdb.java)

---

## Constructors

### `RecordId(String table, long id)` {#constructor-long}

Creates a record ID with a numeric identifier.

```java title="Method Syntax"
new RecordId(table, id)
```

<table>
    <thead>
        <tr>
            <th>Parameter</th>
            <th>Type</th>
            <th>Description</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td><code>table</code> _(required)_</td>
            <td><code>String</code></td>
            <td>The table name.</td>
        </tr>
        <tr>
            <td><code>id</code> _(required)_</td>
            <td><code>long</code></td>
            <td>The numeric record identifier.</td>
        </tr>
    </tbody>
</table>

```java title="Example"
RecordId id = new RecordId("person", 1);
```

### `RecordId(String table, String id)` {#constructor-string}

Creates a record ID with a string identifier.

```java title="Method Syntax"
new RecordId(table, id)
```

<table>
    <thead>
        <tr>
            <th>Parameter</th>
            <th>Type</th>
            <th>Description</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td><code>table</code> _(required)_</td>
            <td><code>String</code></td>
            <td>The table name.</td>
        </tr>
        <tr>
            <td><code>id</code> _(required)_</td>
            <td><code>String</code></td>
            <td>The string record identifier.</td>
        </tr>
    </tbody>
</table>

```java title="Example"
RecordId id = new RecordId("person", "tobie");
```

### `RecordId(String table, UUID id)` {#constructor-uuid}

Creates a record ID with a UUID identifier.

```java title="Method Syntax"
new RecordId(table, id)
```

<table>
    <thead>
        <tr>
            <th>Parameter</th>
            <th>Type</th>
            <th>Description</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td><code>table</code> _(required)_</td>
            <td><code>String</code></td>
            <td>The table name.</td>
        </tr>
        <tr>
            <td><code>id</code> _(required)_</td>
            <td><code>UUID</code></td>
            <td>The UUID record identifier.</td>
        </tr>
    </tbody>
</table>

```java title="Example"
RecordId id = new RecordId("person", UUID.randomUUID());
```

### `RecordId(String table, Array id)` {#constructor-array}

Creates a record ID with a composite key using an array.

```java title="Method Syntax"
new RecordId(table, id)
```

<table>
    <thead>
        <tr>
            <th>Parameter</th>
            <th>Type</th>
            <th>Description</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td><code>table</code> _(required)_</td>
            <td><code>String</code></td>
            <td>The table name.</td>
        </tr>
        <tr>
            <td><code>id</code> _(required)_</td>
            <td><code>Array</code></td>
            <td>The composite key as an array.</td>
        </tr>
    </tbody>
</table>

### `RecordId(String table, Object id)` {#constructor-object}

Creates a record ID with a composite key using an object.

```java title="Method Syntax"
new RecordId(table, id)
```

<table>
    <thead>
        <tr>
            <th>Parameter</th>
            <th>Type</th>
            <th>Description</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td><code>table</code> _(required)_</td>
            <td><code>String</code></td>
            <td>The table name.</td>
        </tr>
        <tr>
            <td><code>id</code> _(required)_</td>
            <td><code>Object</code></td>
            <td>The composite key as an object.</td>
        </tr>
    </tbody>
</table>

---

## Methods

### `.getTable()` {#get-table}

Returns the table name of this record ID.

```java title="Method Syntax"
recordId.getTable()
```

**Returns:** `String`

```java title="Example"
RecordId id = new RecordId("person", "tobie");
String table = id.getTable();
```

### `.getId()` {#get-id}

Returns the identifier part of this record ID.

```java title="Method Syntax"
recordId.getId()
```

**Returns:** [`Id`](#id)

```java title="Example"
RecordId id = new RecordId("person", "tobie");
Id identifier = id.getId();
```

---

## `Id` {#id}

The `Id` class represents the identifier part of a `RecordId`. It wraps the underlying value and provides type checking and extraction methods.

### Static factory methods

#### `Id.from(long id)` {#from-long}

Creates an `Id` from a numeric value.

```java title="Method Syntax"
Id.from(id)
```

<table>
    <thead>
        <tr>
            <th>Parameter</th>
            <th>Type</th>
            <th>Description</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td><code>id</code> _(required)_</td>
            <td><code>long</code></td>
            <td>The numeric identifier.</td>
        </tr>
    </tbody>
</table>

**Returns:** `Id`

#### `Id.from(String id)` {#from-string}

Creates an `Id` from a string value.

```java title="Method Syntax"
Id.from(id)
```

<table>
    <thead>
        <tr>
            <th>Parameter</th>
            <th>Type</th>
            <th>Description</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td><code>id</code> _(required)_</td>
            <td><code>String</code></td>
            <td>The string identifier.</td>
        </tr>
    </tbody>
</table>

**Returns:** `Id`

#### `Id.from(UUID id)` {#from-uuid}

Creates an `Id` from a UUID value.

```java title="Method Syntax"
Id.from(id)
```

<table>
    <thead>
        <tr>
            <th>Parameter</th>
            <th>Type</th>
            <th>Description</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td><code>id</code> _(required)_</td>
            <td><code>UUID</code></td>
            <td>The UUID identifier.</td>
        </tr>
    </tbody>
</table>

**Returns:** `Id`

### Type checking methods

| Method | Returns `true` when |
|---|---|
| `isLong()` | The ID is a numeric value |
| `isString()` | The ID is a string value |
| `isUuid()` | The ID is a UUID value |
| `isArray()` | The ID is a composite array key |
| `isObject()` | The ID is a composite object key |

### Getter methods

| Method | Return Type | Description |
|---|---|---|
| `getLong()` | `long` | Returns the numeric ID value |
| `getString()` | `String` | Returns the string ID value |
| `getUuid()` | `UUID` | Returns the UUID ID value |
| `getArray()` | `Array` | Returns the composite array key |
| `getObject()` | `Object` | Returns the composite object key |

---

## `RecordIdRange` {#record-id-range}

The `RecordIdRange` class represents a range of record IDs within a table. It can be used with methods like `select` to retrieve a subset of records.

### Constructor

#### `RecordIdRange(String table, Id start, Id end)` {#range-constructor}

Creates a range of record IDs. Pass `null` for `start` or `end` to leave that bound open.

```java title="Method Syntax"
new RecordIdRange(table, start, end)
```

<table>
    <thead>
        <tr>
            <th>Parameter</th>
            <th>Type</th>
            <th>Description</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td><code>table</code> _(required)_</td>
            <td><code>String</code></td>
            <td>The table name.</td>
        </tr>
        <tr>
            <td><code>start</code> _(optional)_</td>
            <td><code>Id</code></td>
            <td>The start of the range. Pass <code>null</code> for an unbounded start.</td>
        </tr>
        <tr>
            <td><code>end</code> _(optional)_</td>
            <td><code>Id</code></td>
            <td>The end of the range. Pass <code>null</code> for an unbounded end.</td>
        </tr>
    </tbody>
</table>

### Methods

#### `.getTable()` {#range-get-table}

Returns the table name of this range.

```java title="Method Syntax"
range.getTable()
```

**Returns:** `String`

#### `.getStart()` {#range-get-start}

Returns the start bound of the range, or `null` if unbounded.

```java title="Method Syntax"
range.getStart()
```

**Returns:** `Id` (nullable)

#### `.getEnd()` {#range-get-end}

Returns the end bound of the range, or `null` if unbounded.

```java title="Method Syntax"
range.getEnd()
```

**Returns:** `Id` (nullable)

### Example

```java title="Selecting a range of records"
RecordIdRange range = new RecordIdRange("users", Id.from(1), Id.from(100));
List<Value> results = db.select(range);
```

---

## See also

- [Value](/docs/reference/java/api/values/value.md) - The Value class reference
- [Surreal](/docs/reference/java/api/core/surreal.md) - Connection and method reference
- [Data manipulation](/docs/reference/java/concepts/data-manipulation.md) - Working with records
- [SurrealQL record IDs](/docs/reference/query-language/language-primitives/data-types/record-ids.md) - Record identifier formats and types
