PostgreSQL front-end

Errors, refused statements and known differences

PostgreSQL error codes, what is refused and how the behaviour differs from a real PostgreSQL.

Refused#

Refused clearly with PostgreSQL's SQLSTATE 0A000 (feature_not_supported: X is not supported by this server) or the syntax error PostgreSQL gives at the right position (42601); a script lists them with their output.

  • Programmability: CREATE TYPE of a base, shell or range type, range and multirange types (int4range, tstzrange, ...), CREATE RULE | AGGREGATE | OPERATOR | COLLATION | CAST | LANGUAGE | PUBLICATION | SUBSCRIPTION, CREATE EXTENSION of anything but uuid-ossp, pgcrypto and pg_trgm (extension "x" is unavailable: hstore, citext, unaccent, PostGIS and other extensions written in C), crypt, gen_salt and pgp_* of pgcrypto, word_similarity of pg_trgm, large objects (lo_*), languages other than plpgsql and sql; ADD | DROP ATTRIBUTE of a composite type another composite type stores in a column; in the function of a row trigger of a table (it is translated into an engine trigger): conditions other than others, division_by_zero, raise_exception, the 23xxx ones and literal SQLSTATEs, FOR over a query, record variables (the functions of statement-level, INSTEAD OF and transition-table triggers are interpreted and have none of these limits); RETURNING and ON CONFLICT on a view with INSTEAD OF triggers; a format() format that is not a constant; MERGE .. RETURNING with an INSERT that does not give the primary key or with DEFAULT VALUES; a call of a function with arguments that read columns (except a LANGUAGE sql function that is one SELECT expression), a user-defined set-returning function in the select list; privileges on functions.
  • Storage: CREATE MATERIALIZED VIEW .. WITH NO DATA, declarative partitioning (PARTITION BY, PARTITION OF), INHERITS, CREATE TABLE .. (LIKE ..), index methods other than btree, hash and the text search GIN index, ALTER TABLE .. SET | ENABLE | DISABLE, ALTER .. SET DEFAULT .. of the system, COPY from or to a file or a program, COPY with FORCE_NULL, ON_ERROR, DEFAULT, WHERE, SELECT .. INTO, ON DELETE SET DEFAULT, ALTER COLUMN TYPE .. USING, COMMIT PREPARED.
  • Query features: tsvector / tsquery values outside @@ and the text search functions other than the ones above (ts_rank, ts_headline, setweight, ...), generate_subscripts of a dimension other than 1, virtual generated columns, SIMILAR TO with a pattern that is not a literal, INTERSECT ALL / EXCEPT ALL, WINDOW frames other than as written, comparison of a composite value with a text literal (as in PostgreSQL), SET client_encoding other than UTF8, DateStyle other than ISO.
  • Everything else not listed in "Statements" is 42601 or 42883 (an unknown function: function f(integer) has not been defined).

Known differences from PostgreSQL#

Everything that does not come out identical is listed here; a difference that could be removed was removed, not hidden.

  • DETAIL: Failing row contains (...) of not-null and check violations is not given; the DETAIL: Key (x)=(v) is not present in table ... / is still referenced from ... of foreign-key violations is not given (the engine's error does not carry the row). The ERROR line, SQLSTATE, constraint and table names are PostgreSQL's. Unique violations carry the Key (..)=(..) already exists. detail.
  • Text is compared, sorted and matched by bytes (the C collation: 'a' = 'A' is false, B sorts before a); the comparison cluster is made with --locale=C. GROUP BY, DISTINCT and the unique indexes of text columns still ignore case, as the engine does (D102).
  • Numbers. numeric without a modifier is stored as the engine's PGNUMERIC (D135): each value keeps its own scale, as in PostgreSQL, up to 30 digits after the point (a column of a table made before D135 is a DECIMAL(65,30) and is printed without trailing zeros); NaN and Infinity of numeric do not exist. A quotient has PostgreSQL's scale (D125: 1::numeric / 3 is 0.33333333333333333333, 7::numeric / 2 is 3.5000000000000000; avg of integers and numerics too), also when stored in an unconstrained numeric column or a table made by CREATE TABLE AS. The operands of a division count their own scale as the declared one (a numeric without modifier: the scale of the digits written). The engine's SUM of decimals is exact when the digits fit 128 bits. float4 arithmetic is done in double precision.
  • Fractions of seconds are kept by timestamp, time, interval and the engine's date functions since D123.
  • JSON. jsonb columns print as PostgreSQL stores them; the values the operators ->, ->>, #>, @> return come from the engine's JSON and write 1.50 as 1.5. json (not jsonb) is kept as text. ?, ?| and ?& look at the keys of an object, the elements of an array and a string value (D125).
  • bytea (D125) is the engine text \x + hex digits, lower case (so comparison and ordering of the text are the byte order); input in the hex and the escape form with PostgreSQL's errors, bytea_output = 'escape' in text transfer, length, octet_length, bit_length, encode and decode (hex, base64, escape), ||, substring, position, get_byte, set_byte, md5, convert_to and convert_from (UTF8 only) count and work on bytes. A client that asks for the binary format gets the bytes whatever bytea_output is (D135). timetz, intervals and time zones are done (D126, D123).
  • Arrays (D112.1) are JSON arrays: a number read out of an array has lost its scale unless the type has one (numeric(10,2)[]); ordering comparison and ORDER BY of arrays follow PostgreSQL (numbers compared as double precision); a lower bound other than 1 does not exist; unnest of two dimensions returns the sub-arrays; the array functions over an aggregate (array_length(array_agg(x), 1)) are refused (array_to_string(array_agg(..), sep) works); array_agg of arrays does not check dimensions.
  • pg_dump (D112.2): the plain dump writes a CHECK constraint and a view's query as they were written, where PostgreSQL writes its deparsed form (the restoring server deparses them itself, so the restored \d+ is identical); privileges are not dumped (relacl is NULL); role passwords are not dumped; pg_dump of materialized views, generated columns and objects of several owners was not checked. \d+ of a view shows the stored query text, not PostgreSQL's deparsed text. pg_total_relation_size and friends answer 8192 for everything (so \dt+ sizes differ).
  • LISTEN / NOTIFY (D112.3) work inside one raftdb-pg process; on a TLS connection an idle listener gets its notifications at its next statement; pg_notify needs constant arguments; LISTEN inside an aborted transaction is not undone.
  • Cursors (D112.5) read their rows at DECLARE (a large result is kept in the session); MERGE (D112.4) needs a target with a primary key and runs as several engine statements in one transaction; generated columns show the expression as written (generated always as (a + b) stored: PostgreSQL's deparse can differ for anything but simple expressions).
  • DDL is not transactional (the engine's DDL commits): a CREATE TABLE in a rolled-back transaction stays; ALTER TABLE .. ADD CONSTRAINT .. CHECK failed in the engine after other ALTERs of a table in a long script (cause not found; it works on fresh tables and in CREATE TABLE).
  • Transactions are atomic but not isolated; SET TRANSACTION ISOLATION LEVEL and BEGIN ISOLATION LEVEL are reported by SHOW transaction_isolation but have no effect; row locks (FOR UPDATE) are not taken; statement_timeout and CancelRequest do not interrupt a running statement (the request is counted).
  • Privileges (D110.1): privileges on functions do not exist; column privileges are enforced but \dp does not show them; CONNECT on a database is not checked at login; the owner cannot revoke its own privileges; REVOKE without CASCADE does not check privileges passed on; \dp and relacl show nothing; the lines of a DROP ROLE detail list put a serial sequence before its table and otherwise sort by name (PostgreSQL's is by OID); the owner of public is the server's superuser. Logins, passwords (SCRAM verifiers) and NOLOGIN are enforced. Row-level security does not exist.
  • Functions and triggers (D110.3): (\df, \sf, pg_proc and pg_get_functiondef know the functions since D112.2); (f(..)).col of a function with OUT parameters is not supported; EXECUTE on functions is not checked and SECURITY DEFINER has no effect; variables shadow columns of the same name instead of raising ambiguous; errors raised by statements inside a trigger function lack the CONTEXT: SQL statement lines; UPDATE OF row triggers fire for an update the engine makes by itself (a cascade) whatever columns it changes; transition tables keep the columns the table had when the trigger was made; PL/pgSQL cursors read their rows when opened and stay open after the transaction; pg_trigger_depth() counts the triggers the front-end runs, not the engine's row triggers; the order in which a multi-row UPDATE touches rows (and fires row triggers) is the engine's, not PostgreSQL's heap order; RAISE NOTICE in a trigger function is dropped.
  • COPY (D110.2): no files or programs on the server, no FORCE_NULL, ON_ERROR, DEFAULT, WHERE.
  • UPDATE .. RETURNING reads the primary keys, updates, then reads the rows by key (three engine statements, not atomic with other sessions; the table needs a primary key; RETURNING may name only the target table; a SET of the key column is not followed). INSERT .. ON CONFLICT .. RETURNING needs literal values for the conflict key columns. ON CONFLICT (cols) takes any unique key as the conflict. Simple views are updatable (D126) and information_schema says so (D135). WHERE CURRENT OF needs a table with a primary key whose columns the cursor reads.
  • EXPLAIN prints a plausible plan (Seq Scan on t (cost=.. rows=.. width=..), Nested Loop, Append), not the engine's plan; EXPLAIN ANALYZE times are not measured.
  • Catalogs. Object identifiers are made from names; pg_settings is a short fixed list; pg_get_constraintdef of a CHECK prints the expression as written inside CHECK ((..)) (PostgreSQL prints its own normal form: CHECK ((qty > (0)::numeric))); information_schema.table_constraints does not list the NOT NULL constraints PostgreSQL 18 shows as CHECK; the order of the objects in a DETAIL list of a DROP .. CASCADE is alphabetical (PostgreSQL's is by OID).
  • SHOW ALL lists the parameters the front-end knows; SET of another name is 42704.
  • Multi-statement simple queries (Query message with several statements, which psql sends only with \;) run in an implicit transaction made by the front-end with the engine's START TRANSACTION / COMMIT.
  • GENERATED ALWAYS AS IDENTITY does not refuse an explicit value.
  • Statistics views (pg_stat_*) have PostgreSQL's columns and rows, but their counters are 0 and their times NULL: Raft DB does not keep them. pg_stat_statements does not exist.
  • TABLESAMPLE keeps each row with the given chance (SYSTEM too: PostgreSQL samples pages); which rows are chosen differs from PostgreSQL's choice.
  • jsonb functions work on the engine's JSON: a number written 1.50 comes back as 1.5; json_strip_nulls of a json value writes it without blanks.
  • WITH inside a subquery is rewritten into derived tables; a recursive one inside a subquery stops after 8 levels.

pgbench against PostgreSQL 18 (D110.5)#

pgbench -i and the built-in tpcb-like and select-only scripts run against raftdb-pg. The table below was made with Raft DB's own benchmark script (not part of the download) that runs a private raftdb-pg and a private PostgreSQL 18 on the same Windows laptop, one after the other, nothing else running, below-normal priority, scale 1, 15 s per cell, simple query mode, one run per cell. Caveats that matter: PostgreSQL with default settings and the Raft DB server with its default commit path (durability not made equal here); Raft DB's transactions are not isolated, so the 16-client tpcb-like row (one branch row everybody updates) does not wait for locks as PostgreSQL does and is not comparable; pgbench shares the CPU. This is Raft DB running as PostgreSQL: it is not a basis for speed claims on the website.

workloadclientsRaft DB as PostgreSQL tpslatency msPostgreSQL 18 tpslatency ms
select-only190510.1191570.11
select-only4255610.16274280.15
select-only16455690.35502490.32
tpcb-like17601.3213180.76
tpcb-like419062.1030241.32
tpcb-like1641053.9024326.58

pgbench -i -s 1: 18.3 s on raftdb-pg (the primary keys), 0.4 s on PostgreSQL.

Next#

Declarative partitioning, range types, tsvector values with ts_rank and the other text search functions, a deparser of expressions (so that plain dumps, CHECK constraints, views and index expressions are written exactly as PostgreSQL writes them), privileges on functions, row-level security, isolation.