Skip to content
NEW

Introducing SurrealDB Studio, the new official app of SurrealDB

Learn more

1/6

Course content preview

3: Using the ONLY keyword

SurrealDB returns an array of results by default. But in queries that return a single record, you can add ONLY to return the record itself instead of inside the record contained in an array.

-- Return an array with one record inside
CREATE place;
-- Return one record
CREATE ONLY place;


Response
-------- Query 1 --------

[
  {
    id: place:hke4u4eqkm9lomnma9ac
  }
]

-------- Query 2 --------

{
  id: place:8xi1lvtx785stp7lyy64
}


This is useful when working with the output of a query. Instead of needing to use [0] to pull out the first item at index 0, the output of the query itself is now just a single record.

It is also helpful when using one of the SDKs and you want a response that can be deserialised easily into a single object.

Previous

2: Creating records

Next lesson

4: Non-ASCII record IDs

SurrealDB

The unified data layer for AI

Graph, vector, document, and relational in one engine.
Agent Memory that connects and retrieves context wherever your data lives.

Explore with AI

Stay in the loop

Tutorials, AI agent recipes, and product updates, every two weeks.

Independently verified

SOC 2 Type 2

GDPR

Cyber Essentials Plus

ISO 27001

Trust Centre

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