git.postgresql.org Git - postgresql.git/commitdiff

git projects / postgresql.git / commitdiff
? search:
summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 8c71467)
Fix CREATE DATABASE so we can pg_upgrade DBs with OIDs above 2^31.
Fri, 4 Nov 2022 14:39:52 +0000 (10:39 -0400)
Fri, 4 Nov 2022 14:39:52 +0000 (10:39 -0400)
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


diff --git a/src/backend/commands/dbcommands.c b/src/backend/commands/dbcommands.c
index 16e422138bb7eb1358c377036940e72771190582..8abc2c3e0b0fe7b9307160bbece56bcfc714b905 100644 (file)
--- a/src/backend/commands/dbcommands.c
+++ b/src/backend/commands/dbcommands.c
@@ -816,7 +816,7 @@ createdb(ParseState *pstate, const CreatedbStmt *stmt)
}
else if (strcmp(defel->defname, "oid") == 0)
{
- dboid = defGetInt32(defel);
+ dboid = defGetObjectId(defel);
/*
* We don't normally permit new databases to be created with
diff --git a/src/backend/commands/define.c b/src/backend/commands/define.c
index 86b89071eeddfe51df180db6a63dfa1bb8126c97..090e5d38d24fbb40100c6af6803a718d1e20ae35 100644 (file)
--- 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.
*/
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index 6ca23f88c4f5b8ea5ec6e17f7cfea9ad269fdb76..deb101710e4d651d0d55b3d1060949ddf1ed7b79 100644 (file)
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -11105,9 +11105,9 @@ createdb_opt_items:
;
createdb_opt_item:
- createdb_opt_name opt_equal SignedIconst
+ createdb_opt_name opt_equal NumericOnly
{
- $$ = makeDefElem(1,ドル (Node *) makeInteger(3ドル), @1);
+ $$ = makeDefElem(1,ドル 3ドル, @1);
}
| createdb_opt_name opt_equal opt_boolean_or_string
{
diff --git a/src/include/commands/defrem.h b/src/include/commands/defrem.h
index 56d2bb661612530235249191be86f3ef05e63243..1d3ce246c92703a1bc25915fdab0bf09ee5b402e 100644 (file)
--- a/src/include/commands/defrem.h
+++ b/src/include/commands/defrem.h
@@ -150,6 +150,7 @@ extern double defGetNumeric(DefElem *def);
extern bool defGetBoolean(DefElem *def);
extern int32 defGetInt32(DefElem *def);
extern int64 defGetInt64(DefElem *def);
+extern Oid defGetObjectId(DefElem *def);
extern List *defGetQualifiedName(DefElem *def);
extern TypeName *defGetTypeName(DefElem *def);
extern int defGetTypeLength(DefElem *def);
This is the main PostgreSQL git repository.
RSS Atom

AltStyle によって変換されたページ (->オリジナル) /