Skip to content

Commit 0bd11d9

Browse files
committed
Add comments warning against generalizing default_with_oids.
pg_dump has historically assumed that default_with_oids affects only plain tables and not other relkinds. Conceivably we could make it apply to some newly invented relkind if we did so from the get-go, but changing the behavior for existing object types will break existing dump scripts. Add code comments warning about this interaction. Also, make sure that default_with_oids doesn't cause parse_utilcmd.c to think that CREATE FOREIGN TABLE will create an OID column. I think this is only a latent bug right now, since we don't allow UNIQUE/PKEY constraints in CREATE FOREIGN TABLE, but it's better to be consistent and future-proof.
1 parent 04f1542 commit 0bd11d9

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/backend/commands/tablecmds.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,14 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId,
579579
*/
580580
descriptor = BuildDescForRelation(schema);
581581

582+
/*
583+
* Notice that we allow OIDs here only for plain tables, even though some
584+
* other relkinds can support them. This is necessary because the
585+
* default_with_oids GUC must apply only to plain tables and not any other
586+
* relkind; doing otherwise would break existing pg_dump files. We could
587+
* allow explicit "WITH OIDS" while not allowing default_with_oids to
588+
* affect other relkinds, but it would complicate interpretOidsOption().
589+
*/
582590
localHasOids = interpretOidsOption(stmt->options,
583591
(relkind == RELKIND_RELATION));
584592
descriptor->tdhasoid = (localHasOids || parentOidCount > 0);

src/backend/parser/parse_utilcmd.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,18 @@ transformCreateStmt(CreateStmt *stmt, const char *queryString)
222222
cxt.blist = NIL;
223223
cxt.alist = NIL;
224224
cxt.pkey = NULL;
225-
cxt.hasoids = interpretOidsOption(stmt->options, true);
225+
226+
/*
227+
* Notice that we allow OIDs here only for plain tables, even though
228+
* foreign tables also support them. This is necessary because the
229+
* default_with_oids GUC must apply only to plain tables and not any other
230+
* relkind; doing otherwise would break existing pg_dump files. We could
231+
* allow explicit "WITH OIDS" while not allowing default_with_oids to
232+
* affect other relkinds, but it would complicate interpretOidsOption(),
233+
* and right now there's no WITH OIDS option in CREATE FOREIGN TABLE
234+
* anyway.
235+
*/
236+
cxt.hasoids = interpretOidsOption(stmt->options, !cxt.isforeign);
226237

227238
Assert(!stmt->ofTypename || !stmt->inhRelations); /* grammar enforces */
228239

0 commit comments

Comments
 (0)