Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5189398

Browse files
committed
Handle unqualified SEQUENCE NAME options properly in parse_utilcmd.c.
generateSerialExtraStmts() was sloppy about handling the case whereSEQUENCE NAME is given with a not-schema-qualified name. It was generatinga CreateSeqStmt with an unqualified sequence name, and an AlterSeqStmtwhose "owned_by" DefElem contained a T_String Value with a null stringpointer in the schema-name position. The generated nextval() argument wasalso underqualified. This accidentally failed to fail at runtime, but onlyso long as the current default creation namespace at runtime is the rightnamespace. That's bogus; the parse-time transformation is supposed to beinserting the right schema name in all cases, so as to avoid any possibleskew in that selection. I'm not sure this could fail in pg_dump's usage,but it's still wrong; we have had real bugs in this area before adoptingthe policy that parse_utilcmd.c should generate only fully-qualifiedauxiliary commands. A slightly lesser problem, which is what led me tonotice this in the first place, is that pprint() dumped core on theAlterSeqStmt because of the bogus T_String.Noted while poking into the open problem with ALTER SEQUENCE breakingpg_upgrade.
1 parent4f7a95b commit5189398

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

‎src/backend/parser/parse_utilcmd.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,15 @@ transformCreateStmt(CreateStmt *stmt, const char *queryString)
345345
returnresult;
346346
}
347347

348+
/*
349+
* generateSerialExtraStmts
350+
*Generate CREATE SEQUENCE and ALTER SEQUENCE ... OWNED BY statements
351+
*to create the sequence for a serial or identity column.
352+
*
353+
* This includes determining the name the sequence will have. The caller
354+
* can ask to get back the name components by passing non-null pointers
355+
* for snamespace_p and sname_p.
356+
*/
348357
staticvoid
349358
generateSerialExtraStmts(CreateStmtContext*cxt,ColumnDef*column,
350359
Oidseqtypid,List*seqoptions,boolfor_identity,
@@ -373,7 +382,6 @@ generateSerialExtraStmts(CreateStmtContext *cxt, ColumnDef *column,
373382
* problem, especially since few people would need two serial columns in
374383
* one table.
375384
*/
376-
377385
foreach(option,seqoptions)
378386
{
379387
DefElem*defel=lfirst_node(DefElem,option);
@@ -393,7 +401,17 @@ generateSerialExtraStmts(CreateStmtContext *cxt, ColumnDef *column,
393401
RangeVar*rv=makeRangeVarFromNameList(castNode(List,nameEl->arg));
394402

395403
snamespace=rv->schemaname;
404+
if (!snamespace)
405+
{
406+
/* Given unqualified SEQUENCE NAME, select namespace */
407+
if (cxt->rel)
408+
snamespaceid=RelationGetNamespace(cxt->rel);
409+
else
410+
snamespaceid=RangeVarGetCreationNamespace(cxt->relation);
411+
snamespace=get_namespace_name(snamespaceid);
412+
}
396413
sname=rv->relname;
414+
/* Remove the SEQUENCE NAME item from seqoptions */
397415
seqoptions=list_delete_ptr(seqoptions,nameEl);
398416
}
399417
else
@@ -433,7 +451,9 @@ generateSerialExtraStmts(CreateStmtContext *cxt, ColumnDef *column,
433451
* not our synthetic one.
434452
*/
435453
if (seqtypid)
436-
seqstmt->options=lcons(makeDefElem("as", (Node*)makeTypeNameFromOid(seqtypid,-1),-1),
454+
seqstmt->options=lcons(makeDefElem("as",
455+
(Node*)makeTypeNameFromOid(seqtypid,-1),
456+
-1),
437457
seqstmt->options);
438458

439459
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp