NEW RasterizedDB 1.1.0 is out: sharding and the gateway, the message broker, roles and row-level security, compression, .NET on NuGet, and the enterprise edition. What's new ›
DOCS / RASTERIZEDDB SERVER / QUERYING DATA

Querying data

This page covers SELECT from start to finish: filtering, sorting and paging, joins, subqueries, common table expressions, grouping, set operations, window functions and prepared statements. RasterizedDB reads PostgreSQL's SQL, so a query you already run against PostgreSQL usually runs here unchanged. The places where it does not are listed under Limits.

The functions and operators you can call inside a query are listed in Functions and operators. Locking reads (FOR UPDATE) and what a query sees while other sessions write are covered in Transactions.

Sample data

The examples on this page use these two tables. Run this once to follow along:

sql
CREATE TABLE customers (id INT PRIMARY KEY, name TEXT NOT NULL, tier TEXT);
CREATE TABLE orders (id INT PRIMARY KEY, customer_id INT, total INT, placed DATE);

INSERT INTO customers VALUES (1, 'Ann', 'gold'), (2, 'Bob', 'silver'), (3, 'Cy', NULL);
INSERT INTO orders VALUES
    (1, 1, 10, '2024-01-01'),
    (2, 1, 30, '2024-02-01'),
    (3, 1, 20, '2024-03-01'),
    (4, 2, 5,  '2024-01-05'),
    (5, 2, 50, '2024-01-06');

Selecting columns and expressions

sql
SELECT * FROM customers;
SELECT id, name AS customer_name FROM customers;
SELECT o.id, o.total * 2 AS doubled FROM orders AS o;
SELECT "customers"."name" FROM "customers";
  • * returns every column. t.* returns every column of one relation.
  • AS names an output column. The AS keyword can be left out.
  • Names may be qualified (o.total) or quoted ("customers"."name"). Unquoted names are folded to lower case, as PostgreSQL does.

A SELECT does not need a FROM:

sql
SELECT 1 + 1 AS two, now() AS started, current_database();

TABLE name is short for SELECT * FROM name, and takes ORDER BY and LIMIT:

sql
TABLE customers ORDER BY id LIMIT 1;

SELECT … INTO creates a table from the result, as in PostgreSQL:

sql
SELECT id, total INTO TEMP big_orders FROM orders WHERE total > 15;

For CREATE TABLE … AS SELECT and temporary tables, see Tables and data types.

Filtering with WHERE

sql
SELECT id FROM orders WHERE total >= 20 AND (customer_id = 1 OR placed < '2024-01-10');
SELECT id FROM orders WHERE customer_id IN (1, 3);
SELECT id FROM orders WHERE total NOT BETWEEN 10 AND 30;
SELECT name FROM customers WHERE name LIKE 'A%';
SELECT name FROM customers WHERE name ILIKE 'b%';
SELECT name FROM customers WHERE tier IS NULL;
SELECT name FROM customers WHERE tier IS DISTINCT FROM 'gold';

What you can use in a WHERE:

FormNotes
=, <> / !=, <, <=, >, >=On every type. Text compares by its collation; see Full-text search and collations.
AND, OR, NOT, parenthesesSQL's three-valued logic: a comparison with NULL is unknown, and NOT of unknown is still unknown.
IN (…), NOT IN (…)A list of values, or a subquery (below). NOT IN over a list holding NULL matches nothing, as in PostgreSQL.
BETWEEN a AND b, NOT BETWEENInclusive at both ends.
LIKE, ILIKE, NOT LIKE, SIMILAR TOThe full pattern language, % and _. ILIKE ignores case.
IS NULL, IS NOT NULL
IS [NOT] DISTINCT FROMA comparison that treats two NULLs as equal and never answers unknown.
IS TRUE, IS FALSE, IS NOT TRUE, IS NOT FALSEOn boolean expressions.
x = ANY (array), x > ALL (array)Against an array value or a parameter: WHERE id = ANY($1).
Row values(a, b) > (1, 'x'), see Row-value comparisons.

Regular-expression operators (~, ~*, !~), JSON operators and full-text matching work in a WHERE too. They are listed in Functions and operators, JSON and JSONB and Full-text search and collations.

Sorting and paging

sql
SELECT id, total FROM orders ORDER BY total DESC;
SELECT id, total FROM orders ORDER BY customer_id, placed DESC;
SELECT name, tier FROM customers ORDER BY tier NULLS FIRST;
SELECT id, total * 2 AS doubled FROM orders ORDER BY doubled;
SELECT id, total FROM orders ORDER BY 2 DESC, 1;
SELECT id FROM orders ORDER BY total - customer_id;
  • ASC (the default) and DESC set the direction.
  • NULL sorts after every value in ascending order and before every value in descending order, as in PostgreSQL. NULLS FIRST and NULLS LAST override that.
  • A sort key can be a column that is not selected, an output name (doubled), a position in the select list (2) or any expression.

Pick a page of rows with LIMIT and OFFSET, or with the standard FETCH spelling. They mean the same thing:

sql
SELECT id FROM orders ORDER BY id LIMIT 2 OFFSET 2;
SELECT id FROM orders ORDER BY id OFFSET 2 ROWS FETCH NEXT 2 ROWS ONLY;
SELECT id FROM orders ORDER BY id FETCH FIRST ROW ONLY;
SELECT id FROM orders ORDER BY id LIMIT ALL;

LIMIT and OFFSET accept bound parameters (LIMIT $1 OFFSET $2). LIMIT ALL means no limit. Without an ORDER BY the rows of a page are not in any promised order, so always sort a query you page through.

For deep pages, paging by the last key you saw (keyset paging) is cheaper than a growing OFFSET:

sql
SELECT customer_id, id FROM orders
WHERE (customer_id, id) > (1, 3)
ORDER BY customer_id, id
LIMIT 2;
text
 customer_id | id
-------------+----
           2 |  4
           2 |  5

DISTINCT and DISTINCT ON

SELECT DISTINCT removes duplicate rows. Two NULLs count as duplicates of each other.

sql
SELECT DISTINCT customer_id FROM orders ORDER BY customer_id;

DISTINCT ON (keys) keeps the first row of each group of keys, in the query's ORDER BY order. Use it for "the latest row per key":

sql
SELECT DISTINCT ON (customer_id) customer_id, id, placed
FROM orders
ORDER BY customer_id, placed DESC;
text
 customer_id | id |   placed
-------------+----+------------
           1 |  3 | 2024-03-01
           2 |  5 | 2024-01-06

As in PostgreSQL, the ORDER BY must start with the DISTINCT ON keys (42P10 otherwise). DISTINCT ON also works over joins, grouped queries and window functions.

Joins

All of PostgreSQL's join kinds are available:

sql
-- Inner join: only the pairs that match.
SELECT c.name, o.total FROM customers c JOIN orders o ON o.customer_id = c.id;

-- Left join: every customer, with NULLs where there is no order.
SELECT c.name, o.total FROM customers c LEFT JOIN orders o ON o.customer_id = c.id;

-- Right and full outer joins.
SELECT c.name, o.id FROM customers c RIGHT JOIN orders o ON o.customer_id = c.id;
SELECT c.name, o.id FROM customers c FULL OUTER JOIN orders o ON o.customer_id = c.id;

-- Cross join, written either way.
SELECT c.name, o.id FROM customers c CROSS JOIN orders o;
SELECT c.name, o.id FROM customers c, orders o WHERE o.customer_id = c.id;
  • JOIN and INNER JOIN are the same. LEFT JOIN is LEFT OUTER JOIN.
  • An ON condition can have several equalities (ON a.x = b.x AND a.y = b.y, as a junction table needs) and other conditions besides.
  • JOIN … USING (col, …) joins on columns with the same name and shows each such column once. NATURAL JOIN uses every column the two have in common.
  • A comma join with an equality in the WHERE is planned as the matching inner join, so both spellings cost the same.
  • Any number of relations can be joined, with aliases, and a join can read tables, views, CTEs and derived tables.
sql
CREATE TABLE addresses (customer_id INT PRIMARY KEY, city TEXT);
INSERT INTO addresses VALUES (1, 'Oslo'), (2, 'Turku');

SELECT customer_id, total, city FROM orders JOIN addresses USING (customer_id);

Joins are executed in memory. A join whose intermediate result would pass the join memory budget fails with SQLSTATE 53200 instead of exhausting the server's memory. The budget is 1024 MB by default. Set the RDB_JOIN_MEMORY_MB environment variable for the server process to change it. A join with no equality between two large tables (a cross join) is what usually reaches the budget.

LATERAL

A LATERAL item in the FROM list can read the columns of the items before it. It runs once per outer row. Its most common use is "top N per group":

sql
SELECT c.name, o.total
FROM customers c
CROSS JOIN LATERAL (
    SELECT total FROM orders
    WHERE orders.customer_id = c.id
    ORDER BY total DESC
    LIMIT 2
) o
ORDER BY c.name, o.total DESC;
text
 name | total
------+-------
 Ann  |    30
 Ann  |    20
 Bob  |    50
 Bob  |     5

Use LEFT JOIN LATERAL … ON true to keep outer rows the item has nothing for:

sql
SELECT c.name, o.total
FROM customers c
LEFT JOIN LATERAL (
    SELECT total FROM orders WHERE orders.customer_id = c.id ORDER BY total DESC LIMIT 1
) o ON true
ORDER BY c.name;
text
 name | total
------+-------
 Ann  |    30
 Bob  |    50
 Cy   |

A LATERAL item can also be VALUES or a set-returning function. A function in FROM can read earlier items even without the LATERAL keyword, as in PostgreSQL, and WITH ORDINALITY numbers its rows:

sql
SELECT c.name, g FROM customers c, LATERAL generate_series(1, c.id) g ORDER BY 1, 2;
SELECT c.id, u.v, u.n
FROM customers c
CROSS JOIN LATERAL unnest(ARRAY[c.id * 10, c.id * 20]) WITH ORDINALITY AS u(v, n);
SELECT c.name, t.v FROM customers c CROSS JOIN LATERAL (VALUES (c.id * 10), (c.id * 100)) t(v);

Subqueries

Scalar subqueries

A subquery in parentheses that returns one column and at most one row can be used as a value. It can read the outer query's columns (a correlated subquery):

sql
SELECT c.name,
       (SELECT max(total) FROM orders o WHERE o.customer_id = c.id) AS biggest
FROM customers c
ORDER BY c.name;
text
 name | biggest
------+---------
 Ann  |      30
 Bob  |      50
 Cy   |

A scalar subquery that returns more than one row fails with SQLSTATE 21000; one that returns no row is NULL.

IN, EXISTS, ANY and ALL

sql
SELECT name FROM customers WHERE id IN (SELECT customer_id FROM orders WHERE total > 25);
SELECT name FROM customers WHERE id NOT IN (SELECT customer_id FROM orders WHERE total > 25);
SELECT name FROM customers c WHERE EXISTS (SELECT 1 FROM orders o WHERE o.customer_id = c.id);
SELECT name FROM customers c WHERE NOT EXISTS (SELECT 1 FROM orders o WHERE o.customer_id = c.id);
SELECT id FROM orders WHERE total > ANY (SELECT total FROM orders WHERE customer_id = 2);
SELECT id FROM orders WHERE total >= ALL (SELECT total FROM orders);
  • IN, NOT IN, = ANY, SOME and ALL follow PostgreSQL's NULL rules: NOT IN against a subquery that returns a NULL matches nothing.
  • An IN subquery that returns no rows makes IN false and NOT IN true.
  • A row can be compared with a subquery's rows: WHERE (customer_id, total) IN (SELECT customer_id, max(total) FROM orders GROUP BY customer_id).
  • Inside a subquery, an outer column can be named without its table, as PostgreSQL scopes names: the subquery's own tables first, then each enclosing query's.

Derived tables

A subquery in FROM is a derived table. It needs an alias, and the alias can rename its columns:

sql
SELECT s.cid, s.spent
FROM (SELECT customer_id, sum(total) FROM orders GROUP BY customer_id) AS s(cid, spent)
WHERE s.spent > 50;

A table alias can rename a table's columns the same way: FROM orders AS o(oid, cid).

Common table expressions (WITH)

WITH names a query so the statement can read it like a table. A name can have a column list, and several CTEs can be chained, each reading the ones before it:

sql
WITH spend (customer_id, spent) AS (
    SELECT customer_id, sum(total) FROM orders GROUP BY customer_id
),
big AS (
    SELECT customer_id FROM spend WHERE spent > 50
)
SELECT c.name FROM customers c JOIN big ON big.customer_id = c.id;

Each CTE is computed once, before the statement that reads it, however many times it is referenced. A filter written in the outer query is not pushed into the CTE, so put selective conditions inside the CTE's own query. AS MATERIALIZED and AS NOT MATERIALIZED are accepted.

A CTE can also be an INSERT, UPDATE or DELETE … RETURNING; see Modifying data.

Recursive CTEs

WITH RECURSIVE runs a non-recursive term once, then the recursive term repeatedly over the rows the previous round added, until a round adds none. UNION ALL keeps every row; UNION removes duplicates, which also stops a walk over a cycle.

sql
CREATE TABLE categories (id INT PRIMARY KEY, parent INT, name TEXT);
INSERT INTO categories VALUES
    (1, NULL, 'root'), (2, 1, 'a'), (3, 1, 'b'), (4, 2, 'a1'), (5, 4, 'a1x');

WITH RECURSIVE tree (id, path, depth) AS (
    SELECT id, name, 0 FROM categories WHERE parent IS NULL
    UNION ALL
    SELECT c.id, t.path || '/' || c.name, t.depth + 1
    FROM categories c JOIN tree t ON c.parent = t.id
)
SELECT id, path, depth FROM tree ORDER BY path;
text
 id |      path       | depth
----+-----------------+-------
  1 | root            |     0
  2 | root/a          |     1
  4 | root/a/a1       |     2
  5 | root/a/a1/a1x   |     3
  3 | root/b          |     1

The whole recursion is computed before the outer query reads it, so an outer LIMIT does not stop an endless recursion. Put the stopping condition in the recursive term (WHERE n < 100). A recursion that runs more than 10,000 rounds, or produces more than 10,000,000 rows, is stopped with an error. For a plain series of numbers use generate_series.

Grouping and aggregates

sql
SELECT customer_id, count(*) AS orders, sum(total) AS spent, avg(total) AS average
FROM orders
GROUP BY customer_id
HAVING sum(total) > 50
ORDER BY spent DESC;
  • Group by columns, by expressions (GROUP BY date_trunc('month', placed)), by an output name, or by position (GROUP BY 1).
  • A select-list expression over the grouped columns is allowed: SELECT customer_id * 10, count(*) FROM orders GROUP BY customer_id.
  • Grouping by a table's primary key lets you select that table's other columns without listing them, as in PostgreSQL.
  • HAVING filters groups and can use aggregates and grouped columns.
  • count(DISTINCT x) and the other aggregates with DISTINCT count each distinct value once.
  • FILTER (WHERE …) restricts the rows one aggregate sees: count(*) FILTER (WHERE total > 20).
  • sum and avg over integer and NUMERIC columns are exact; a money amount keeps its cents.

The available aggregate functions are listed in Functions and operators.

ROLLUP, CUBE and GROUPING SETS

sql
SELECT customer_id, placed, sum(total)
FROM orders
GROUP BY ROLLUP (customer_id, placed)
ORDER BY 1, 2;

SELECT customer_id, placed, count(*), GROUPING(customer_id, placed)
FROM orders
GROUP BY CUBE (customer_id, placed);

SELECT customer_id, placed, count(*)
FROM orders
GROUP BY GROUPING SETS ((customer_id), (placed), ());

The rolled-up rows show NULL in the columns they total over. GROUPING(…) tells a subtotal's NULL apart from a real one.

Set operations

sql
SELECT customer_id FROM orders UNION SELECT id FROM customers;
SELECT customer_id FROM orders UNION ALL SELECT id FROM customers;
SELECT id FROM customers INTERSECT SELECT customer_id FROM orders;
SELECT id FROM customers EXCEPT SELECT customer_id FROM orders;
  • UNION, INTERSECT and EXCEPT remove duplicates; with ALL they keep them (INTERSECT ALL keeps a row as often as both sides have it, EXCEPT ALL as often as the left side has it more).
  • INTERSECT binds tighter than UNION and EXCEPT, which apply left to right. Parentheses group branches: (SELECT 1 UNION SELECT 2) INTERSECT SELECT 2.
  • A trailing ORDER BY, LIMIT, OFFSET or FETCH applies to the whole result. To limit one branch, put it in parentheses: (SELECT … ORDER BY x LIMIT 1) UNION ALL (SELECT …).
  • Branches must have the same number of columns, and each column's types must be of one family (42804 otherwise). Integers of different widths are widened to the wider one.

Window functions

A window function computes a value for each row from a set of related rows, without collapsing them as GROUP BY does.

sql
SELECT id, customer_id, total,
       row_number() OVER (PARTITION BY customer_id ORDER BY placed) AS nth,
       sum(total)   OVER (PARTITION BY customer_id ORDER BY placed) AS running,
       sum(total)   OVER (PARTITION BY customer_id) AS customer_total,
       lag(total, 1) OVER (PARTITION BY customer_id ORDER BY placed) AS previous
FROM orders
ORDER BY customer_id, placed;
text
 id | customer_id | total | nth | running | customer_total | previous
----+-------------+-------+-----+---------+----------------+----------
  1 |           1 |    10 |   1 |      10 |             60 |
  2 |           1 |    30 |   2 |      40 |             60 |       10
  3 |           1 |    20 |   3 |      60 |             60 |       30
  4 |           2 |     5 |   1 |       5 |             55 |
  5 |           2 |    50 |   2 |      55 |             55 |        5
  • PARTITION BY splits the rows into groups; ORDER BY orders each group. With an ORDER BY an aggregate is a running total; without one it covers the whole partition.
  • The ranking and value functions are row_number, rank, dense_rank, percent_rank, cume_dist, ntile, lag, lead, first_value, last_value and nth_value. The aggregates sum, avg, count, min and max work as window functions too. See Functions and operators.
  • An aggregate used as a window function accepts FILTER (WHERE …).
  • A named window avoids repeating a definition:
sql
SELECT id, sum(total) OVER w AS running
FROM orders
WINDOW w AS (PARTITION BY customer_id ORDER BY id)
ORDER BY id;

Frames

A frame chooses which rows of the partition an aggregate, first_value, last_value or nth_value reads:

sql
SELECT id, sum(total) OVER (ORDER BY id ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) FROM orders;
SELECT id, sum(total) OVER (ORDER BY total RANGE BETWEEN 5 PRECEDING AND 5 FOLLOWING) FROM orders;
SELECT id, sum(total) OVER (ORDER BY total GROUPS BETWEEN 1 PRECEDING AND CURRENT ROW) FROM orders;
SELECT id, sum(total) OVER (ORDER BY id ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW EXCLUDE CURRENT ROW) FROM orders;
SELECT id, last_value(total) OVER (ORDER BY id ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) FROM orders;
  • ROWS, RANGE and GROUPS frames, with UNBOUNDED PRECEDING, n PRECEDING, CURRENT ROW, n FOLLOWING and UNBOUNDED FOLLOWING.
  • EXCLUDE CURRENT ROW, EXCLUDE GROUP, EXCLUDE TIES and EXCLUDE NO OTHERS.
  • The default frame is PostgreSQL's: from the start of the partition to the current row and its peers when there is an ORDER BY, the whole partition when there is not.
  • GROUPS needs an ORDER BY, and a RANGE frame with an offset needs exactly one ORDER BY column (42P20 otherwise, as in PostgreSQL).

Row-value comparisons

Two rows of the same length compare column by column, left to right, as PostgreSQL compares them:

sql
SELECT id FROM orders WHERE (customer_id, total) > (1, 20) ORDER BY customer_id, total;
SELECT id FROM orders WHERE (customer_id, total) = (2, 50);
SELECT id FROM orders WHERE (customer_id, id) IN (SELECT customer_id, max(id) FROM orders GROUP BY customer_id);

All six comparison operators work. Rows of different lengths are an error. ROW(a, b) is the same as (a, b).

CASE

Both forms of CASE work anywhere a value does: the select list, WHERE, ORDER BY, GROUP BY, and UPDATE … SET.

sql
SELECT id,
       CASE WHEN total >= 30 THEN 'large' WHEN total >= 10 THEN 'medium' ELSE 'small' END AS size,
       CASE customer_id WHEN 1 THEN 'Ann' WHEN 2 THEN 'Bob' ELSE 'other' END AS who
FROM orders;

A CASE without ELSE gives NULL when no branch matches. Its result type is the common type of its branches, as PostgreSQL works it out.

COALESCE, NULLIF, GREATEST and LEAST are in Functions and operators.

Casts and typed literals

sql
SELECT '42'::int + 1, CAST(total AS text), total::numeric(10, 2) / 3 FROM orders;
SELECT DATE '2024-02-29' + 1, INTERVAL '90 minutes', TIMESTAMP '2024-01-01 12:00:00';
SELECT id FROM orders WHERE placed >= '2024-02-01'::date;
  • expr::type and CAST(expr AS type) are the same. Type modifiers apply: ::varchar(3), ::numeric(10, 2), ::timestamp(0).
  • A typed literal (DATE '…', TIMESTAMP '…', INTERVAL '…') is a value of that type.
  • A string that cannot be read as the target type fails with PostgreSQL's error code (22P02 for bad input, 22003 for a number out of range).

The types themselves are described in Tables and data types.

Sampling rows

TABLESAMPLE reads a random sample of a table:

sql
SELECT count(*) FROM orders TABLESAMPLE BERNOULLI (50);
SELECT * FROM orders TABLESAMPLE SYSTEM (10);

The argument is the percentage of rows to keep. SYSTEM samples rows, not pages, so it behaves like BERNOULLI.

Locking reads

SELECT … FOR UPDATE, FOR NO KEY UPDATE, FOR SHARE and FOR KEY SHARE, with NOWAIT or SKIP LOCKED, lock the rows a query returns. They are how a job queue claims work. How the locks behave is described in Transactions.

Prepared statements

Through a driver

Drivers and ORMs prepare statements through PostgreSQL's extended query protocol: the statement is sent once with $1, $2, … placeholders, and each execution sends only the values. RasterizedDB supports it in full, with parameters in text or binary format, and describes each statement's parameter and result types before it runs. Use your driver's normal parameter binding; never build SQL by pasting values into strings.

With SQL

PREPARE, EXECUTE and DEALLOCATE do the same from SQL, for tools such as psql. A prepared statement belongs to the session that prepared it.

sql
PREPARE orders_of (int) AS
    SELECT id, total FROM orders WHERE customer_id = $1 ORDER BY id;

EXECUTE orders_of(1);
EXECUTE orders_of(2);

DEALLOCATE orders_of;
  • The type list after the name is optional. When given, each argument is read as that type.
  • EXECUTE puts each argument in place of its $n and runs the statement as if it had been sent, so the body can be a SELECT, a WITH query or a write.
  • DEALLOCATE ALL drops every prepared statement of the session. DEALLOCATE PREPARE name is accepted too.
ErrorSQLSTATE
PREPARE of a name the session already prepared42P05
EXECUTE or DEALLOCATE of a name the session has not prepared26000

Seeing how a query runs

EXPLAIN shows how a query will be executed: which relations are scanned, the filters applied to each scan and how they are joined. It does not name the index a scan will use; see Is my index used?.

Limits

These are the differences from PostgreSQL in querying. Each is refused with an error (most with SQLSTATE 0A000) rather than answered wrongly.

  • FETCH … WITH TIES is not supported. FETCH FIRST n ROWS ONLY is.
  • Recursive CTEs are computed in full before the outer query reads them: an outer LIMIT does not end a recursion, and a recursion is stopped after 10,000 rounds or 10,000,000 rows. The SEARCH and CYCLE clauses are not supported; use UNION to stop at a cycle.
  • CTEs are always computed once, in full, before the statement that reads them (PostgreSQL 12 and later may inline them).
  • RANGE frames with an offset (RANGE BETWEEN 5 PRECEDING AND …) need a numeric ORDER BY column: integers, NUMERIC or floating point. A date or timestamp key with an interval offset is refused.
  • LATERAL:
    • SELECT * over a LATERAL subquery is refused. Name its columns.
    • RIGHT JOIN LATERAL and FULL JOIN LATERAL are refused.
    • A LATERAL item that reads two of the items before it is refused, as is a LATERAL item first in the FROM list.
  • Correlated scalar subqueries are refused in some places. Write them as a join or a LATERAL join instead:
    • in a grouped query, inside a larger select-list expression or in the ORDER BY;
    • in a query grouped by an expression;
    • in a query with a window function;
    • when the subquery has no FROM.
  • A correlated EXISTS whose subquery has GROUP BY or HAVING is refused.
  • Set operations:
    • A date column in one branch against a timestamp column in another is refused. Cast the date (d::timestamp).
    • An untyped string constant in the first branch, beside a typed column in a later branch (SELECT '5' UNION ALL SELECT id FROM orders), is refused. Cast the constant ('5'::integer).
  • TABLESAMPLE … REPEATABLE (seed) is refused: a sample is drawn anew on every run.
  • Joins run in memory, within a budget (1024 MB by default, RDB_JOIN_MEMORY_MB). A join that passes it fails with 53200.
  • generate_series and unnest return at most 1,000,000 rows per call.
✓ page rendered in 216 µs axum + tera + htmx · no other javascript