Skip to main content

SQL overview

You talk to CamusDB in SQL, so the skills, queries, and tools you already use with a relational database carry over. CamusDB accepts common PostgreSQL expression forms, such as :: casts, so SQL that an ORM or a PostgreSQL tool generates usually needs few changes. Where CamusDB differs, these pages say so.

Run SQL from application code with the .NET, TypeScript, or Python driver. They bind values and handle the transport; the SQL reference does not require knowledge of JSON requests or gRPC messages. For interactive use, choose camus-cli or the Web Console.

The dialect covers what you expect from a relational database, plus a few additions:

  • Schemas with CHECK constraints, foreign keys, sequences, identity columns, views, and materialized views.
  • Queries with inner, outer, and cross joins, subqueries, derived tables, aggregates, window functions, and CASE expressions.
  • Writes with INSERT ... SELECT and RETURNING.
  • Serializable transactions, time-travel reads, vector search, row-level TTL, users and grants, and a large library of scalar functions.

This page covers the parts that belong to CamusDB alone and maps each statement to its page.

CREATE DATABASE IF NOT EXISTS app;

CREATE TABLE robots (
id OID PRIMARY KEY NOT NULL,
name STRING NOT NULL,
year INT64 DEFAULT (2024)
);

CREATE INDEX robots_year_idx ON robots (year DESC);

INSERT INTO robots (id, name, year)
VALUES (GEN_ID(), "R2-D2", 1977);

SELECT id, name, year
FROM robots
WHERE year >= 1970
ORDER BY year DESC;

Identifiers and case​

Keywords are not case-sensitive. CamusDB stores database, table, column, and index names in the case you use when you create or rename them, and later lookups ignore case:

CREATE TABLE Robots (
Id OID PRIMARY KEY NOT NULL,
RobotName STRING NOT NULL
);

INSERT INTO robots (id, robotname) VALUES (GEN_ID(), "R2-D2");
SELECT ROBOTNAME FROM ROBOTS;

The result still shows the original names Robots, Id, and RobotName, and so do SHOW TABLES, SHOW COLUMNS, and SHOW CREATE TABLE. robots, ROBOTS, and Robots all refer to the same table.

Names are also unique regardless of case, so Robots and robots cannot be two tables in the same database, and one table cannot have both RobotName and robotname columns.

Backticks​

Use backticks when an identifier matches a reserved keyword, a type name, or a function name:

CREATE TABLE `order` (
`select` STRING NOT NULL,
`from` STRING
);

SELECT `select`, `from`
FROM `order`;

CASE, END, and OVER are reserved, so a column named end needs SELECT `end` FROM events.

Literals​

Backticks quote identifiers only. String literals use single or double quotation marks, and the two forms are equivalent:

SELECT "literal text", 'literal text';

See Data Types for the literal format of every type, including temporal values, arrays, and object ids.

Comments​

CamusDB accepts both line and block comments. A comment is valid anywhere a space is: before a statement, between clauses, or at the end of a line.

-- Line comments run to the end of the line.
SELECT id, name
FROM robots
WHERE year >= 1980; -- only newer robots

/*
Block comments span multiple lines.
*/
SELECT id, name
FROM robots /* or sit inline */
WHERE active = true;

Block comments do not nest: the first */ closes the comment. An unterminated comment is a parser error.

A comment marker inside a string literal is just text:

SELECT "not -- a comment" AS value;

One point is easy to miss: -- always starts a comment, so SELECT 10 FROM t --5 parses as SELECT 10 FROM t. To subtract a negative number, write 10 - -5, with a space.

Statement map​

Schema​

TaskPage
Create, rename, and drop databasesDatabases
Branch a databaseDatabase Branching
Restore a dropped database or tableRecover Dropped Objects
Tables, columns, and ALTER TABLETables And Columns
Column types and literalsData Types
CHECK and NOT NULLCheck Constraints
Parent-child integrityForeign Keys
CREATE INDEX, DROP INDEX, and covering indexesIndexes
GIN indexes for JSONBJSON Indexes
Sequences and identity columnsSequences
Descriptions on schema objectsSchema Comments
Column compression and out-of-line storageLarge Values
A stored queryViews
A stored query result and REFRESH MATERIALIZED VIEWMaterialized Views

Read and write​

TaskPage
INSERT, UPDATE, DELETE; LIMIT on updates and deletesInsert, Update, Delete
RETURNING from inserts, updates, and deletesReturn Changed Rows
ON CONFLICT, UPSERTSkip or Update Conflicting Rows
INSERT ... SELECT and CTASCopying Query Results
TRUNCATE, which empties a tableEmptying A Table
SELECT, filtering, grouping, sorting, and paginationSELECT
FOR UPDATE, NOWAIT, SKIP LOCKEDLock Rows Before Updating Them
Ranking, running totals, and comparisons between rowsWindow Functions
Joins, subqueries, derived tablesJoins And Subqueries
UNION, INTERSECT, EXCEPT, including ALLCombine Query Results
A historical snapshotTime-Travel Reads
A SELECT with no table sourceSELECT Without FROM
JSONB documents, operators, and updatesJSON Documents
PostgreSQL-style casts, arrays, and expression formsPostgreSQL Expression Syntax
Scalar functionsFunctions
Generate rows with generate_seriesSet-Returning Functions
Custom C# functions, row triggers, and CALL proceduresC# Extensions
Vectors and nearest neighbor searchVector Search
Row expiryRow-Level TTL

Transactions, performance, and inspection​

TaskPage
BEGIN, COMMIT, ROLLBACK, isolation, and locksTransactions In SQL
Snapshot behavior and isolation guaranteesTransactions And Isolation
Retry a transaction after a conflictRetries And Conflicts
Transaction size and lifetime limitsTransaction Limits
SET TRANSACTION PRIORITYTransaction Priority
How CamusDB selects a planQuery Planning
How to read a planEXPLAIN
The estimates behind a planSHOW STATISTICS
Refresh optimizer statistics with ANALYZEAutomatic Analyze
Caching repeated readsResult Cache
Spill large query buffers to temporary filesSpill To Disk
Scans across the clusterDistributed Queries
Learn routes for repeated SQLSQL Routing Advice
The range placement of a table or indexSHOW RANGES
Active queries, connections, and CANCEL QUERYQuery Activity
Statements that crossed a slow-query thresholdSlow Query Log
Repeated query costs with SHOW STATEMENT STATSStatement Statistics
Index reads and writes with SHOW INDEX USAGEIndex Usage
Storage and replication metrics with SHOW ENGINE STATSEngine Stats
Effective configuration with SHOW VARIABLESSHOW VARIABLES
Placeholders and prepared handlesParameters And Prepared Statements
A deeply nested generated statementStatement Nesting Limit
List databases, tables, columns, and indexesInspecting The Database
Users, passwords, GRANT, and REVOKEAuthentication And Authorization
SET/RESET CLUSTER SETTING and SHOW CLUSTER SETTINGSRuntime Cluster Settings