Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Queries

Goal

Reference for supported query forms: CTE, JOIN, aggregation, sorting, and statistical surfaces.

Non-recursive WITH (CTE)

AngaraBase supports limited (non-recursive) CTEs as a derived source in FROM:

WITH recent AS (
 SELECT id, v FROM t WHERE v > 100
)
SELECT r.id, r.v
FROM recent r
ORDER BY r.id;

Supported CTE projection forms

WITH c AS (SELECT id, v FROM t)
SELECT * FROM c WHERE id < 10;

Explicitly unsupported

  • WITH RECURSIVE0A000 feature_not_supported
  • Data-modifying CTEs (WITH ... INSERT/UPDATE/DELETE) — 0A000 feature_not_supported

JOINs

SELECT a.id, b.name
FROM orders a
INNER JOIN customers b ON a.customer_id = b.id;

SELECT a.id, b.name
FROM orders a
LEFT JOIN customers b ON a.customer_id = b.id;

Supported are: INNER JOIN, LEFT JOIN.

ORDER BY

SELECT * FROM t ORDER BY v;
SELECT * FROM t ORDER BY v ASC;
SELECT * FROM t ORDER BY v DESC;

ORDER BY <expr> supports limited scalar expressions already supported by the engine.

Support for aliases

ORDER BY can reference aliases defined in the SELECT list using the AS keyword. This works for both regular columns and aggregation results:

-- Alias for an expression
SELECT x * 2 AS doubled FROM t ORDER BY doubled;

-- Alias for aggregation
SELECT grp, sum(amount) AS total 
FROM t 
GROUP BY grp 
ORDER BY total DESC;

Column ordinals

Sorting by the ordinal number of a column in the SELECT list (1-based) is supported, according to the SQL:2011 standard:

-- Sort by the first column (a)
SELECT a, b FROM t ORDER BY 1;

-- Sort by the second column (b) in descending order
SELECT a, b FROM t ORDER BY 2 DESC;

If the specified ordinal is out of range for the number of columns in the query (or equals 0), a 42P10 (invalid_column_reference) error is returned.

NULL ordering

  • In ASC order, NULL is treated as the largest value (appears last).
  • In DESC order, NULL appears first.
  • Explicit NULLS FIRST / NULLS LAST is not supported0A000.

GROUP BY / HAVING

SELECT v, COUNT(*) AS cnt
FROM t
GROUP BY v
HAVING COUNT(*) > 1;

LIMIT / OFFSET

SELECT * FROM t ORDER BY id LIMIT 10;
SELECT * FROM t ORDER BY id LIMIT 10 OFFSET 20;

Expression Errors

When incompatible types are used in arithmetic expressions (for example, attempting to add a string to a number 'string' + 1), AngaraBase returns a 42883 (undefined_function / operator not found) error.

Note: string literals containing numbers (e.g., '123') may be automatically cast to a numeric type depending on the context.

Unsupported query forms

FormSQLSTATE
UNION / INTERSECT / EXCEPT0A000
Window functions (OVER (...))0A000
ORDER BY ... NULLS FIRST|LAST0A000
WITH RECURSIVE0A000
Data-modifying CTEs0A000

AngaraStat surfaces

AngaraBase provides built-in statistical views.

sys.table_stats

ColumnDescription
stats_level_maxMax collection level configured
last_committed_rowidLast committed row ID
last_insert_epochEpoch of last insert
last_mutation_epochEpoch of last mutation

sys.column_stats

ColumnDescription
ndv_approxApproximate number of distinct values (HLL)
col_minColumn minimum (typed Value)
col_maxColumn maximum (typed Value)
null_countNumber of NULLs
stats_epochStats collection epoch
hll_enabledWhether HLL tracking is active
histogram_boundsEqui-depth histogram boundaries (Level 2)
mcv_valuesMost common values (Level 2)
mcv_frequenciesMCV frequencies (Level 2)
reservoir_sizeReservoir sample size (Level 2)
reservoir_epochReservoir epoch (Level 2)
reservoir_drift_countDrift count since last reservoir refresh (Level 2)
SELECT * FROM sys.table_stats WHERE table_name = 'events';
SELECT * FROM sys.column_stats WHERE table_name = 'events' AND column_name = 'ts';

Expected SQLSTATE

SituationSQLSTATE
WITH RECURSIVE0A000
Data-modifying CTE0A000
UNION / INTERSECT / EXCEPT0A000
Window functions0A000
ORDER BY ... NULLS FIRST|LAST0A000
ORDER BY ordinal out of range42P10
Expression type error42883