From 2c6d43650d16d91a3e731d236315beffd98db729 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Fri, 4 Nov 2022 10:39:52 -0400 Subject: Fix CREATE DATABASE so we can pg_upgrade DBs with OIDs above 2^31. Commit aa0105141 repeated one of the oldest mistakes in our book: thinking that OID is the same as int32. It isn't of course, and unsurprisingly the first person who came along with a database OID above 2 billion broke it. Repair. Per bug #17677 from Sergey Pankov. Back-patch to v15. Discussion: https://postgr.es/m/17677-a99fa067d7ed71c9@postgresql.org --- src/backend/commands/define.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'src/backend/commands/define.c') diff --git a/src/backend/commands/define.c b/src/backend/commands/define.c index 0755ab1eae5..1e07fa97bb9 100644 --- a/src/backend/commands/define.c +++ b/src/backend/commands/define.c @@ -213,6 +213,39 @@ defGetInt64(DefElem *def) return 0; /* keep compiler quiet */ } +/* + * Extract an OID value from a DefElem. + */ +Oid +defGetObjectId(DefElem *def) +{ + if (def->arg == NULL) + ereport(ERROR, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("%s requires a numeric value", + def->defname))); + switch (nodeTag(def->arg)) + { + case T_Integer: + return (Oid) intVal(def->arg); + case T_Float: + + /* + * Values too large for int4 will be represented as Float + * constants by the lexer. Accept these if they are valid OID + * strings. + */ + return DatumGetObjectId(DirectFunctionCall1(oidin, + CStringGetDatum(castNode(Float, def->arg)->fval))); + default: + ereport(ERROR, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("%s requires a numeric value", + def->defname))); + } + return 0; /* keep compiler quiet */ +} + /* * Extract a possibly-qualified name (as a List of Strings) from a DefElem. */ -- cgit v1.2.3