Skip to content

SurrealQL

SurrealQL

SurrealQL is SurrealDB's query language. Syntax is broadly SQL-like, with extensions for nested fields, graph edges, record IDs, and other SurrealDB-specific constructs.

For a guided introduction, see Learn: Querying.

A minimal query can follow a familiar SQL shape:

-- Setup
CREATE user:ann CONTENT {
    name: 'Ann',
    age: 34,
    metadata: {
        date_registered: d'2025-01-10T09:00:00Z',
        last_login: d'2026-11-01T18:30:00Z'
    }
};

SELECT name,
       metadata
FROM   user
WHERE  age >= 18; 

Projections can include nested objects and graph traversals:

-- Setup
CREATE user:ann CONTENT {
    name: 'Ann',
    age: 34,
    metadata: {
        date_registered: d'2025-01-10T09:00:00Z',
        last_login: d'2026-11-01T18:30:00Z'
    }
};
CREATE post:one CONTENT { title: 'Hello' };
RELATE user:ann->wrote->post:one;

SELECT name,
       metadata.{
          date_registered,
          last_login
       },
       ->wrote->post AS posts
FROM user
WHERE age >= 18;

Further detail is organised under Statements and the other sections in this reference.

  • Clauses - the clauses statements share, such as WHERE, LIMIT, START and OMIT

Reference pages for the pieces a query is built from:

  • Statements - what a statement is, and how several combine into one query

  • Comments - the three comment forms SurrealQL accepts

  • Data types - every value type, from records to geometries

  • Operators - comparison, arithmetic, set and graph operators

  • Casting - converting a value from one type to another

  • Idioms - path syntax for reaching into records and graphs

  • Parameters - built-in parameters and your own

  • Formatters - formatting datetimes and numbers

  • Record links - pointing at another record

  • Record references - links the database keeps in step for you

Was this page helpful?

Last updated