Skip to content
NEW BENCHMARKS

SurrealDB 3.x by the numbers

View

1/3

Course content preview

7: Field order in objects

Now that all the place records that we used for testing are deleted, let's create the one library that we will use in this tour. This time it will have three fields besides an id: a name, an address, and the number of floors. To do this, we can use SET along with the names of these fields and a value for each.

CREATE place:surreal_library SET
name = "Surreal Library",
address = "2025 Statement Street, Riverdale",
place_type = "library",
floors = 8;

While the fields inside the CREATE statement weren't in alphabetical order, the output always will be.

[
{
address: '2025 Statement Street, Riverdale',
floors: 8,
id: library:76wabj5zw4g4qcuy9o3y,
name: 'Surreal Library',
place_type: 'library'
}
]

This behaviour is because anything can be compared and ordered in SurrealDB. Even objects can be compared, because their fields are lined up alphabetically and compared in that order.

This next example returns true because the value 9 for floors (alphabetically the first field) in the first object is greater than 8 in the second.

{
floors: 9,
name: 'A Library'
} > {
floors: 8,
name: 'Surreal Library'
};

But if you change name to a_name it will now be compared before floors. And because "A Library" (which starts with A) is less than "Surreal Library" (which starts with S), the output is now false.

{
floors: 9,
a_name: 'A Library'
} > {
floors: 8,
a_name: 'Surreal Library'
};
SurrealDB

The context layer for AI agents.

Documents, graphs, vectors, time-series, and memory - in one transaction, one query, one deployment.

Explore with AI

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