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

Commitc4ebf7b

Browse files
committed
Parser was dropping foreign-key constraints on the floor if present in
an ALTER TABLE ADD COLUMN command. Per bug #896.
1 parentf4a72f7 commitc4ebf7b

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

‎src/backend/parser/analyze.c

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
*$Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.263 2003/02/1320:45:21 tgl Exp $
9+
*$Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.264 2003/02/1322:50:01 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -111,7 +111,8 @@ static void transformTableConstraint(ParseState *pstate,
111111
staticvoidtransformIndexConstraints(ParseState*pstate,
112112
CreateStmtContext*cxt);
113113
staticvoidtransformFKConstraints(ParseState*pstate,
114-
CreateStmtContext*cxt);
114+
CreateStmtContext*cxt,
115+
boolisAddConstraint);
115116
staticvoidapplyColumnNames(List*dst,List*src);
116117
staticList*getSetColTypes(ParseState*pstate,Node*node);
117118
staticvoidtransformForUpdate(Query*qry,List*forUpdate);
@@ -777,7 +778,7 @@ transformCreateStmt(ParseState *pstate, CreateStmt *stmt,
777778
/*
778779
* Postprocess foreign-key constraints.
779780
*/
780-
transformFKConstraints(pstate,&cxt);
781+
transformFKConstraints(pstate,&cxt, false);
781782

782783
/*
783784
* Output results.
@@ -1287,7 +1288,8 @@ transformIndexConstraints(ParseState *pstate, CreateStmtContext *cxt)
12871288
}
12881289

12891290
staticvoid
1290-
transformFKConstraints(ParseState*pstate,CreateStmtContext*cxt)
1291+
transformFKConstraints(ParseState*pstate,CreateStmtContext*cxt,
1292+
boolisAddConstraint)
12911293
{
12921294
if (cxt->fkconstraints==NIL)
12931295
return;
@@ -1296,16 +1298,16 @@ transformFKConstraints(ParseState *pstate, CreateStmtContext *cxt)
12961298
cxt->stmtType);
12971299

12981300
/*
1299-
* For ALTER TABLE ADD CONSTRAINT, nothing to do. For CREATE TABLE,
1300-
* gin up an ALTER TABLE ADD CONSTRAINT command to execute after
1301-
* the basicCREATE TABLE is complete.
1301+
* For ALTER TABLE ADD CONSTRAINT, nothing to do. For CREATE TABLE or
1302+
*ALTER TABLE ADD COLUMN,gin up an ALTER TABLE ADD CONSTRAINT command
1303+
*to execute afterthe basiccommand is complete.
13021304
*
13031305
* Note: the ADD CONSTRAINT command must also execute after any index
13041306
* creation commands. Thus, this should run after
13051307
* transformIndexConstraints, so that the CREATE INDEX commands are
13061308
* already in cxt->alist.
13071309
*/
1308-
if (strcmp(cxt->stmtType,"CREATE TABLE")==0)
1310+
if (!isAddConstraint)
13091311
{
13101312
AlterTableStmt*alterstmt=makeNode(AlterTableStmt);
13111313
List*fkclist;
@@ -2257,7 +2259,7 @@ transformAlterTableStmt(ParseState *pstate, AlterTableStmt *stmt,
22572259
(ColumnDef*)stmt->def);
22582260

22592261
transformIndexConstraints(pstate,&cxt);
2260-
transformFKConstraints(pstate,&cxt);
2262+
transformFKConstraints(pstate,&cxt, false);
22612263

22622264
((ColumnDef*)stmt->def)->constraints=cxt.ckconstraints;
22632265
*extras_before=nconc(*extras_before,cxt.blist);
@@ -2294,9 +2296,10 @@ transformAlterTableStmt(ParseState *pstate, AlterTableStmt *stmt,
22942296
elog(ERROR,"Unexpected node type in ALTER TABLE ADD CONSTRAINT");
22952297

22962298
transformIndexConstraints(pstate,&cxt);
2297-
transformFKConstraints(pstate,&cxt);
2299+
transformFKConstraints(pstate,&cxt, true);
22982300

22992301
Assert(cxt.columns==NIL);
2302+
/* fkconstraints should be put into my own stmt in this case */
23002303
stmt->def= (Node*)nconc(cxt.ckconstraints,cxt.fkconstraints);
23012304
*extras_before=nconc(*extras_before,cxt.blist);
23022305
*extras_after=nconc(cxt.alist,*extras_after);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp