Keyed lookup

Key-index point lookup. A keyed table behaves like a big dict: table[key] resolves the receiver to a table (not a value) and does an order-preserving btree point lookup, returning the stored row — or null when the key is absent (Redis GET → nil). It is an ordinary expression, so it composes and rides the bare select <expr> form. v1 covers single-column AND composite full-key literal lookups, plus partial-key (leading-prefix) lookups that return the sub-sequence of matching rows as an array, in key order (empty on no match).

Indexing By

Indexing by an existing int key returns the whole row.

SQL

create table t (id int);

insert into t ({id: 1, v: "a"});

select t[1];

Result

[
  { "id": 1, "v": "a" }
]

Nil Row

A missing key yields null (dict-get → nil), one row.

SQL

create table t (id int);

insert into t ({id: 1, v: "a"});

select t[99];

Result

[
  null
]

Indexing An

Indexing an empty table yields null.

SQL

create table t (id int);

select t[1];

Result

[
  null
]

Get String Key

A string-keyed table indexes by a string literal.

SQL

create table t (id int);

create table s (id string);

insert into s ({id: "x", v: 9});

select s["x"];

Result

[
  { "id": "x", "v": 9 }
]

Re-inserting A

Re-inserting a key overwrites; the lookup sees the latest value.

SQL

create table t (id int);

insert into t ({id: 1, v: 100});

insert into t ({id: 1, v: 200});

select t[1];

Result

[
  { "id": 1, "v": 200 }
]

The Looked-up

The looked-up row is a value and can be indexed further.

SQL

create table t (id int);

insert into t ({id: 1, v: "a"});

select t[1].v;

Result

[
  "a"
]

The Lookup

The lookup picks exactly one row out of many, ignoring the rest.

SQL

create table t (id int);

insert into t ({id: 1, v: "a"}, {id: 2, v: "b"}, {id: 3, v: "c"});

select t[2];

Result

[
  { "id": 2, "v": "b" }
]

Get Wrong Type

A string key against an int-keyed table is a schema error.

SQL

create table t (id int);

select t["a"];

Expected error: schema

Get Keyless

A keyless table cannot be indexed by key.

SQL

create table t (id int);

create table k;

select k[1];

Expected error: static

Get Composite Arity

A key tuple longer than the key-column count is a static error.

SQL

create table t (id int);

create table c (a int, b int);

select c[1, 2, 3];

Expected error: static

Matching Row

A full composite key returns the one matching row.

SQL

create table t (id int);

create table c (a string, b int);

insert into c ({a: "x", b: 7, v: "hit"});

select c["x", 7];

Result

[
  { "a": "x", "b": 7, "v": "hit" }
]

Key Order

A leading-prefix key returns the matching rows as an array in key order.

SQL

create table t (id int);

create table c (a string, b int);

insert into c ({a: "x", b: 2, v: "q"}, {a: "x", b: 1, v: "p"}, {a: "y", b: 9, v: "r"});

select c["x"];

Result

[
  [ { "a": "x", "b": 1, "v": "p" }, { "a": "x", "b": 2, "v": "q" } ]
]

Empty Array

A partial key matching no rows yields an empty array.

SQL

create table t (id int);

create table c (a string, b int);

insert into c ({a: "x", b: 1, v: "p"});

select c["z"];

Result

[
  []
]

Matching Prefix

A two-column prefix of a three-column key scans only the matching prefix.

SQL

create table t (id int);

create table k (a string, b int, c int);

insert into k ({a: "x", b: 7, c: 2, v: "n"}, {a: "x", b: 7, c: 1, v: "m"}, {a: "x", b: 8, c: 9, v: "o"});

select k["x", 7];

Result

[
  [ { "a": "x", "b": 7, "c": 1, "v": "m" }, { "a": "x", "b": 7, "c": 2, "v": "n" } ]
]

The Sub-sequence

The sub-sequence array composes — index into it.

SQL

create table t (id int);

create table c (a string, b int);

insert into c ({a: "x", b: 1, v: "p"}, {a: "x", b: 2, v: "q"});

select c["x"][0];

Result

[
  { "a": "x", "b": 1, "v": "p" }
]

The Sub-sequence

The sub-sequence array composes — scan it as a value source.

SQL

create table t (id int);

create table c (a string, b int);

insert into c ({a: "x", b: 1, v: "p"}, {a: "x", b: 2, v: "q"}, {a: "y", b: 9, v: "r"});

select r from c["x"] as r;

Result

[
  { "a": "x", "b": 1, "v": "p" },
  { "a": "x", "b": 2, "v": "q" }
]

Get Composite Miss

A full composite key with no matching row yields null.

SQL

create table t (id int);

create table c (a string, b int);

insert into c ({a: "x", b: 7});

select c["x", 8];

Result

[
  null
]

Indexing A

Indexing a name that is neither a binding nor a table is unbound.

SQL

create table t (id int);

select ghost[1];

Expected error: static