Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
c4ebf7b1
Commit
c4ebf7b1
authored
Feb 13, 2003
by
Tom Lane
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Parser was dropping foreign-key constraints on the floor if present in
an ALTER TABLE ADD COLUMN command. Per bug #896.
parent
f4a72f77
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
10 deletions
+13
-10
src/backend/parser/analyze.c
src/backend/parser/analyze.c
+13
-10
No files found.
src/backend/parser/analyze.c
View file @
c4ebf7b1
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.26
3 2003/02/13 20:45:2
1 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.26
4 2003/02/13 22:50:0
1 tgl Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -111,7 +111,8 @@ static void transformTableConstraint(ParseState *pstate,
...
@@ -111,7 +111,8 @@ static void transformTableConstraint(ParseState *pstate,
static
void
transformIndexConstraints
(
ParseState
*
pstate
,
static
void
transformIndexConstraints
(
ParseState
*
pstate
,
CreateStmtContext
*
cxt
);
CreateStmtContext
*
cxt
);
static
void
transformFKConstraints
(
ParseState
*
pstate
,
static
void
transformFKConstraints
(
ParseState
*
pstate
,
CreateStmtContext
*
cxt
);
CreateStmtContext
*
cxt
,
bool
isAddConstraint
);
static
void
applyColumnNames
(
List
*
dst
,
List
*
src
);
static
void
applyColumnNames
(
List
*
dst
,
List
*
src
);
static
List
*
getSetColTypes
(
ParseState
*
pstate
,
Node
*
node
);
static
List
*
getSetColTypes
(
ParseState
*
pstate
,
Node
*
node
);
static
void
transformForUpdate
(
Query
*
qry
,
List
*
forUpdate
);
static
void
transformForUpdate
(
Query
*
qry
,
List
*
forUpdate
);
...
@@ -777,7 +778,7 @@ transformCreateStmt(ParseState *pstate, CreateStmt *stmt,
...
@@ -777,7 +778,7 @@ transformCreateStmt(ParseState *pstate, CreateStmt *stmt,
/*
/*
* Postprocess foreign-key constraints.
* Postprocess foreign-key constraints.
*/
*/
transformFKConstraints
(
pstate
,
&
cxt
);
transformFKConstraints
(
pstate
,
&
cxt
,
false
);
/*
/*
* Output results.
* Output results.
...
@@ -1287,7 +1288,8 @@ transformIndexConstraints(ParseState *pstate, CreateStmtContext *cxt)
...
@@ -1287,7 +1288,8 @@ transformIndexConstraints(ParseState *pstate, CreateStmtContext *cxt)
}
}
static
void
static
void
transformFKConstraints
(
ParseState
*
pstate
,
CreateStmtContext
*
cxt
)
transformFKConstraints
(
ParseState
*
pstate
,
CreateStmtContext
*
cxt
,
bool
isAddConstraint
)
{
{
if
(
cxt
->
fkconstraints
==
NIL
)
if
(
cxt
->
fkconstraints
==
NIL
)
return
;
return
;
...
@@ -1296,16 +1298,16 @@ transformFKConstraints(ParseState *pstate, CreateStmtContext *cxt)
...
@@ -1296,16 +1298,16 @@ transformFKConstraints(ParseState *pstate, CreateStmtContext *cxt)
cxt
->
stmtType
);
cxt
->
stmtType
);
/*
/*
* For ALTER TABLE ADD CONSTRAINT, nothing to do. For CREATE TABLE
,
* For ALTER TABLE ADD CONSTRAINT, nothing to do. For CREATE TABLE
or
*
gin up an ALTER TABLE ADD CONSTRAINT command to execute after
*
ALTER TABLE ADD COLUMN, gin up an ALTER TABLE ADD CONSTRAINT command
* t
he basic CREATE TABLE
is complete.
* t
o execute after the basic command
is complete.
*
*
* Note: the ADD CONSTRAINT command must also execute after any index
* Note: the ADD CONSTRAINT command must also execute after any index
* creation commands. Thus, this should run after
* creation commands. Thus, this should run after
* transformIndexConstraints, so that the CREATE INDEX commands are
* transformIndexConstraints, so that the CREATE INDEX commands are
* already in cxt->alist.
* already in cxt->alist.
*/
*/
if
(
strcmp
(
cxt
->
stmtType
,
"CREATE TABLE"
)
==
0
)
if
(
!
isAddConstraint
)
{
{
AlterTableStmt
*
alterstmt
=
makeNode
(
AlterTableStmt
);
AlterTableStmt
*
alterstmt
=
makeNode
(
AlterTableStmt
);
List
*
fkclist
;
List
*
fkclist
;
...
@@ -2257,7 +2259,7 @@ transformAlterTableStmt(ParseState *pstate, AlterTableStmt *stmt,
...
@@ -2257,7 +2259,7 @@ transformAlterTableStmt(ParseState *pstate, AlterTableStmt *stmt,
(
ColumnDef
*
)
stmt
->
def
);
(
ColumnDef
*
)
stmt
->
def
);
transformIndexConstraints
(
pstate
,
&
cxt
);
transformIndexConstraints
(
pstate
,
&
cxt
);
transformFKConstraints
(
pstate
,
&
cxt
);
transformFKConstraints
(
pstate
,
&
cxt
,
false
);
((
ColumnDef
*
)
stmt
->
def
)
->
constraints
=
cxt
.
ckconstraints
;
((
ColumnDef
*
)
stmt
->
def
)
->
constraints
=
cxt
.
ckconstraints
;
*
extras_before
=
nconc
(
*
extras_before
,
cxt
.
blist
);
*
extras_before
=
nconc
(
*
extras_before
,
cxt
.
blist
);
...
@@ -2294,9 +2296,10 @@ transformAlterTableStmt(ParseState *pstate, AlterTableStmt *stmt,
...
@@ -2294,9 +2296,10 @@ transformAlterTableStmt(ParseState *pstate, AlterTableStmt *stmt,
elog
(
ERROR
,
"Unexpected node type in ALTER TABLE ADD CONSTRAINT"
);
elog
(
ERROR
,
"Unexpected node type in ALTER TABLE ADD CONSTRAINT"
);
transformIndexConstraints
(
pstate
,
&
cxt
);
transformIndexConstraints
(
pstate
,
&
cxt
);
transformFKConstraints
(
pstate
,
&
cxt
);
transformFKConstraints
(
pstate
,
&
cxt
,
true
);
Assert
(
cxt
.
columns
==
NIL
);
Assert
(
cxt
.
columns
==
NIL
);
/* fkconstraints should be put into my own stmt in this case */
stmt
->
def
=
(
Node
*
)
nconc
(
cxt
.
ckconstraints
,
cxt
.
fkconstraints
);
stmt
->
def
=
(
Node
*
)
nconc
(
cxt
.
ckconstraints
,
cxt
.
fkconstraints
);
*
extras_before
=
nconc
(
*
extras_before
,
cxt
.
blist
);
*
extras_before
=
nconc
(
*
extras_before
,
cxt
.
blist
);
*
extras_after
=
nconc
(
cxt
.
alist
,
*
extras_after
);
*
extras_after
=
nconc
(
cxt
.
alist
,
*
extras_after
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment