SQL & Postgres β Reference
Lookup material for the SQL subset. For prose and examples see the Guide; to get started, the Quickstart.
Operator & function quick reference
Everything the subset accepts, at a glance. Anything not listed is rejected
loudly (with SQLSTATE 0A000 / 42601), never silently ignored.
| Category | Supported |
|---|---|
| Comparison | =, <> / !=, <, <=, >, >= |
| Set / range | IN (β¦), NOT IN (β¦), BETWEEN a AND b |
| Null | IS NULL, IS NOT NULL (= NULL rejected β use IS NULL) |
| Text match | LIKE 'ap%' (prefix) or exact, NOT LIKE β no %ap, %ap%, _, or ILIKE |
| Full-text | col @@ 'text' or to_tsvector(col) @@ plainto_tsquery('text') β tokenising $match on an analysed column. See Guide |
| Boolean logic | AND, OR, NOT, parentheses |
| Arithmetic | +, -, *, /, parentheses, precedence |
| String fns | || (concat), concat, upper, lower, length |
| Scalar fns | coalesce(a, b, β¦), cast(x AS int|bigint|text|numeric|β¦) |
| Aggregates | count(*), count(DISTINCT c), sum, avg, min, max β usable inside expressions |
| Prediction | predict(col) (argmax), predictions(col) β‘ predict(col, probabilities => true) (distribution); PREDICTION/PREDICTIONS aliases β inference in SQL; not with GROUP BY. See the Guide |
| Recommend | SELECT * FROM recommend('from','target', goal => 'β¦', given => 'β¦', k => N) β set-returning function β (value, p). See the Guide |
| Relate | SELECT * FROM relate('from', fields => 'β¦', to => 'β¦', k => N) β set-returning function β (related, lift, info, n). See the Guide |
| Clauses | WHERE, GROUP BY (single col), HAVING, ORDER BY β¦ ASC|DESC (single key), LIMIT, OFFSET |
| Join | INNER JOIN β¦ ON <base>.<fk> = <joined>.<pk>, along a declared link |
Not supported yet (rejected with a clear error, never silently ignored):
multiple ORDER BY keys, outer/cross/multi-table JOIN (and joins whose ON
is not a declared link), multi-column GROUP BY, per-group min/max,
UNION, substring/suffix LIKE and ILIKE, subqueries, and
schema-qualified/quoted identifiers. = NULL / <> NULL are rejected with a hint
to use IS NULL / IS NOT NULL (matching Postgres's three-valued logic).
(INSERT, CREATE TABLE, and CREATE VIEW are supported over the Postgres
wire protocol β see Writes β but not on the
read-only /api/v2/_sql endpoint.)
Error codes (SQLSTATE)
Failures are reported with a standard PostgreSQL SQLSTATE, so a Postgres
client or connector reacts the way it would to a real Postgres β the message is
always specific, never a swallowed empty result. Over the wire protocol the code
rides in the ErrorResponse; over REST it's in the error JSON.
| SQLSTATE | Name | When |
|---|---|---|
23505 | unique_violation | INSERT of a duplicate primary key with no (or DO NOTHING-less) ON CONFLICT |
42P07 | duplicate_table | CREATE TABLE / CREATE VIEW of a name that exists (without IF NOT EXISTS / OR REPLACE) |
42P01 | undefined_table | SELECT / INSERT / UPDATE / DELETE / ALTER / DROP on a missing table or view |
42701 | duplicate_column | ALTER TABLE ADD COLUMN of a column that exists |
42703 | undefined_column | reference to a column that doesn't exist (ALTER DROP, unknown SET/select column) |
0A000 | feature_not_supported | a valid-Postgres construct Aito doesn't implement yet (outer join, subquery, ILIKE, β¦) |
42601 | syntax_error | a parse error, or an argument the subset rejects (= NULL, '%ap%', a type mismatch) |
XX000 | internal_error | an unexpected server-side failure |
IF [NOT] EXISTS turns the otherwise-erroring redundant case (42P07 / 42P01 /
42701 / 42703) into a silent no-op, exactly as in Postgres.
Limitations
- JOINs follow existing links only: an
INNER JOINalong a declared link works (it projects through the link β see the Guide), so a tool that sees the foreign key can run the join. Arbitrary joins on non-link columns, and outer/cross/multi-table joins, are still rejected β so apostgres_fdwremote join pushdown across two foreign tables isn't supported (join them locally, or disable join pushdown on the foreign server). - Writes β
INSERT(withON CONFLICT),CREATE TABLE,COPY β¦ FROM STDIN(bulk load),DROP/ALTER TABLE ADD|DROP COLUMN,DELETE, andUPDATEwork over the wire protocol (see Writes); the/api/v2/_sqlREST endpoint is read-only. - Views β
CREATE [OR REPLACE] VIEW v AS SELECT <cols / renames / *> FROM src [WHERE <equalityβ¦>]andDROP VIEW [IF EXISTS] vwork over the wire protocol (see Views). A view is a materialised, from-able collection, not stored SELECT text, soSELECT β¦ FROM vβ including a query-timeWHERE/ORDER BY/GROUP BYand evenpredict/@@β runs on it, and a queryWHEREcomposes on top of the view's baked filter. The view stays current via incremental refresh. v1 limits: a single source (noUNION/JOINin the definition), and a bakedWHEREof equality conditions only (col = v [AND β¦]); a range/IN/LIKEin a view definition, or an aggregate/GROUP BY, is rejected loud atCREATE VIEW(do it at query time against the view instead). - Inference β
predict/predictions(categorical label columns; not analysed-text/multi-value), full-text@@,recommend(...), andrelate(...)are in SQL. Still JSON-only: the raw learned-ranking blends (similarity Γ contextual$p) β those live in the JSON_queryAPI. - Metadata depth β no composite/unique/check constraints, sequences, indexes, or functions; unrecognised catalog queries return empty rather than erroring, so deep tool features may show nothing.
- Wire protocol β no SCRAM channel binding (
-PLUS) or client-certificate auth; TLS is optional, not enforced. Cursors (DECLARE/FETCH) are read-only and materialize the whole result up front (fine for the connectors above, not a streaming cursor over a huge table).
Related
- Query Reference β the JSON query language
_sqllowers to. - Relationships, Links & Joins β how a SQL JOIN maps to an Aito link.
- Environments & Auth β API keys and environments.