| From: | PG Bug reporting form <noreply(at)postgresql(dot)org> |
|---|---|
| To: | pgsql-bugs(at)lists(dot)postgresql(dot)org |
| Cc: | adamkpickering(at)gmail(dot)com |
| Subject: | BUG #19543: ALTER RULE ... RENAME accepts reserved name "_RETURN" for a non-view rule; breaks a restored dump |
| Date: | 2026-07-03 23:26:57 |
| Message-ID: | 19543-461228e77f3b32fc@postgresql.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-bugs |
The following bug has been logged on the website:
Bug reference: 19543
Logged by: Adam Pickering
Email address: adamkpickering(at)gmail(dot)com
PostgreSQL version: 18.4
Operating system: Debian (using an official postgres docker image)
Description:
PostgreSQL version
Official postgres container from dockerhub (Debian 18.4-1.pgdg13+1) on
aarch64-unknown-linux-gnu, compiled by gcc (Debian 14.2.0-19) 14.2.0, 64-bit
(also observed on 17.10 and current 14)
Platform
aarch64, Debian 13-based (official postgres:18 image), Linux 6.6, default
server config.
Description
CREATE RULE rejects the name _RETURN for a rule that is not an ON SELECT
rule. ALTER RULE ... RENAME does not: an existing ON UPDATE/INSERT/DELETE
rule on an ordinary table can be renamed to _RETURN and the server accepts
it. A subsequent pg_dump emits a CREATE RULE "_RETURN" ... statement the
server rejects on reload, so the database can be dumped but not restored.
Exact steps to reproduce (run with psql -X, no ~/.psqlrc)
CREATE TABLE t (a int);
CREATE RULE r AS ON UPDATE TO t DO ALSO SELECT 1;
-- rejected
CREATE RULE "_RETURN" AS ON UPDATE TO t DO ALSO SELECT 1;
-- accepted; this is the bug
ALTER RULE r ON t RENAME TO "_RETURN";
then:
$ createdb fresh
$ pg_dump -t t --no-owner | psql -X -d fresh -v ON_ERROR_STOP=1
Output I got:
CREATE TABLE
CREATE RULE
ERROR: 42P17: non-view rule for "t" must not be named "_RETURN"
LOCATION: DefineQueryRewrite, rewriteDefine.c:456
ALTER RULE
The CREATE RULE "_RETURN" is rejected (expected); the ALTER RULE ... RENAME
TO "_RETURN" reports ALTER RULE, i.e. it succeeds. pg_dump then produces
CREATE RULE "_RETURN" AS ON UPDATE TO public.t DO SELECT 1 ..., and
reloading it fails with the same 42P17 error.
Output I expected:
ALTER RULE ... RENAME TO "_RETURN" rejected the same way CREATE RULE rejects
it, so _RETURN can only ever be a view's ON SELECT rule and any relation
that dumps cleanly can be reloaded.
Context
The guard on CREATE RULE was added deliberately (commit by Tom Lane,
released in 14.3 / 13.7 / 12.11 / 11.16 / 10.23, "Disallow rules named
_RETURN that are not ON SELECT"; the in-tree comment states it "prevents
accidentally or maliciously replacing a view's ON SELECT rule with some
other kind of rule").
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Baji Shaik | 2026-07-03 23:54:16 | Re: uuidv7 improperly accepts dates before 1970-01-01 |
| Previous Message | Zsolt Parragi | 2026-07-03 19:54:14 | Re: uuidv7 improperly accepts dates before 1970-01-01 |