From 30914a4d6cca239bc69f585c104f9a05df091e90 Mon Sep 17 00:00:00 2001 From: Maurice Date: Sat, 28 Nov 2026 00:05:17 +0100 Subject: [PATCH] fix(postgres): keep plugin columns named like PostgreSQL 19's new functions Besides uuid, 19 brings error_on_null, tid_block, tid_offset and oid8 to the catalog, and since the catalog list is the same for every server the guard refused a plugin's s.error_on_null column on 14 to 18 too, where it had always passed. error_on_null and the tuple id parts only read their argument and join the allowlist, where PGPLUG-022 checks their overloads; oid8 only converts, like oid, and joins the column names. --- server/assets/postgres/plugin-functions.txt | 7 +++++++ server/src/db/engine/postgres/plugin-sql-functions.ts | 4 ++-- .../tests/unit/db/engine/postgres/plugin-sql-guard.test.ts | 2 ++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/server/assets/postgres/plugin-functions.txt b/server/assets/postgres/plugin-functions.txt index 918aa1db7..0c19da2f1 100644 --- a/server/assets/postgres/plugin-functions.txt +++ b/server/assets/postgres/plugin-functions.txt @@ -184,6 +184,13 @@ uuid varbit varchar +# Values new in PostgreSQL 19 that read only their argument: a check that raises on NULL, +# and the block and offset of a tuple id a plugin builds itself (the ctid column stays +# refused). Listed so a plugin column of the same name keeps working on every server. +error_on_null +tid_block +tid_offset + # JSON. array_to_json json_agg diff --git a/server/src/db/engine/postgres/plugin-sql-functions.ts b/server/src/db/engine/postgres/plugin-sql-functions.ts index ea491b0aa..870485b75 100644 --- a/server/src/db/engine/postgres/plugin-sql-functions.ts +++ b/server/src/db/engine/postgres/plugin-sql-functions.ts @@ -72,13 +72,13 @@ export const SESSION_KEYWORDS: ReadonlySet = new Set([ * returns a single value (`FROM unnest(...) u`, `FROM generate_series(...) * g`) or a parameter (`$1.f`), that value is the argument. None of these * reads anything called that way: `version` takes no argument, so the - * notation never calls it, and `money`, `name`, `oid` and `xml` only + * notation never calls it, and `money`, `name`, `oid`, `oid8` and `xml` only * convert their argument to the type of that name. Every other refused name * is refused after a dot too. `xid` is not here: `u.xid` casts `u` to the * transaction id type, whose `age()` reads the server's transaction counter. * PGPLUG-021 holds each name here to that on the lane's server. */ -export const COLUMN_NAMES: ReadonlySet = new Set(['money', 'name', 'oid', 'version', 'xml']); +export const COLUMN_NAMES: ReadonlySet = new Set(['money', 'name', 'oid', 'oid8', 'version', 'xml']); /** The function names of `pg_catalog` on every supported major, one per line, sorted. */ export const CATALOG_FUNCTIONS_FILE = path.join( diff --git a/server/tests/unit/db/engine/postgres/plugin-sql-guard.test.ts b/server/tests/unit/db/engine/postgres/plugin-sql-guard.test.ts index f68a65513..43939439d 100644 --- a/server/tests/unit/db/engine/postgres/plugin-sql-guard.test.ts +++ b/server/tests/unit/db/engine/postgres/plugin-sql-guard.test.ts @@ -106,6 +106,8 @@ describe('plugin SQL guard', () => { 'CREATE INDEX ON notes (body)', // PostgreSQL 19 added a uuid() conversion to the catalog; a uuid column and the cast still pass. 'SELECT t.uuid FROM items t WHERE t.uuid = uuid($1)', + // So did error_on_null, tid_block, tid_offset and oid8; a plugin column of that name still passes. + 'SELECT s.error_on_null, s.tid_block, s.tid_offset, s.oid8 FROM settings s', ])('lets through %s', (sql) => { expect(() => check(sql)).not.toThrow(); });