Skip to content
Course content preview

5: Parentheses, indexing, and fields

The first item in an array is at index 0, so you can use [0] to grab it.

["first", "second", "third"][0];


Output
'first'


Since it's impossible to always know the last index number of an array, the last element uses its own character: [$].

["first", "second", "third"][$];


Output
'third'


And since statements like CREATE return an array of results, you might want to pull out the result at a certain index too.

But if you just add [0] at the end of a CREATE statement it won't work, because the [0] in place[0] applies to place (which is just a table name), not to the result of CREATE place.

CREATE place[0];


Output
"Can not execute CREATE statement using value 'NONE'"


To fix it, surround the whole statement in parentheses first.

(CREATE place)[0];


Records have an object-like structure that holds keys (fields) and values. You can access a single field by using a dot and then the field name.

{
name: "Surreal library",
id: place:surreal_library
}.id;


Output
place:surreal_library


As above, you can surround a statement in parentheses and then choose a field to return.

Accessing a single field

(CREATE place).id;


The output is an array of IDs, because .id tells the database to go through the array and only gather the values of the id field.

Output
[
  place:exqlj50tybc6yb1wjrx3
]


If you want to access more than one field, you can give the output a structure by adding a {} after the dot and putting the field names inside there.

Accessing multiple fields

(CREATE place SET place_type = "library", num_books = 10000).{
place_type,
num_books
};


Output
[
  {
    num_books: 10000,
    place_type: 'library'
  }
]


THE PLATFORM

Everything an application and its agents know. Five surfaces, one engine.

IN PRODUCTION

Trusted at scale. Samsung, Nvidia, Verizon, Tencent, and Walmart run on SurrealDB.

14,000+

Developers building on SurrealDB Cloud

4M+

Developers building on SurrealDB worldwide

FROM THE TEAMS

SurrealDB gives us a foundation where we can unify semantic search, knowledge graphs, and AI-driven decision making without stitching together multiple systems. Collapsing responsibility into SurrealDB has become our default engineering posture.
Justin Foley

VP of Engineering, Later

SurrealDB

The context and memory layer for AI agents

Database. Graphs, vectors, documents and relational data in one engine, in a single ACID transaction.
Agent Memory. Connects and retrieves context wherever your data lives, every fact carrying its source.
Cloud. Fully managed, in the cloud provider and region you choose.

Explore with AI

Copyright © 2026 SurrealDB Ltd. Registered in England and Wales. Company no. 13615201

Registered address: 3rd Floor 1 Ashley Road, Altrincham, Cheshire, WA14 2DT, United Kingdom

Trading address: Huckletree Oxford Circus, 213 Oxford Street, London, W1D 2LG, United Kingdom