summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas G. Lockhart1998-09-16 14:25:37 +0000
committerThomas G. Lockhart1998-09-16 14:25:37 +0000
commit7c30ac961f1f319f17f8aad666a073543fc9c773 (patch)
treeff1232c6cd70b390b2641cab2583faf5108b502c
parent198bcef0259831695dc907578be332a4b990822d (diff)
Support specifying PRIMARY KEY for the SERIAL type.
Check for a constraint if is_sequence is set and omit making a UNIQUE index if so, since the primary key will cover that for us.
-rw-r--r--src/backend/parser/analyze.c23
1 files changed, 16 insertions, 7 deletions
diff --git a/src/backend/parser/analyze.c b/src/backend/parser/analyze.c
index 2d2ab420145..dc29f347cf4 100644
--- a/src/backend/parser/analyze.c
+++ b/src/backend/parser/analyze.c
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.86 1998/09/03 14:21:06 thomas Exp $
+ * $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.87 1998/09/16 14:25:37 thomas Exp $
*
*-------------------------------------------------------------------------
*/
@@ -530,11 +530,26 @@ transformCreateStmt(ParseState *pstate, CreateStmt *stmt)
constraint->def = cstring;
constraint->keys = NULL;
+ /* The parser only allows PRIMARY KEY as a constraint for the SERIAL type.
+ * So, if there is a constraint of any kind, assume it is that.
+ * If PRIMARY KEY is specified, then don't need to gin up a UNIQUE constraint
+ * since that will be covered already.
+ * - thomas 1998-09-15
+ */
if (column->constraints != NIL)
+ {
column->constraints = lappend(column->constraints, constraint);
+ }
else
+ {
column->constraints = lcons(constraint, NIL);
+ constraint = makeNode(Constraint);
+ constraint->contype = CONSTR_UNIQUE;
+ constraint->name = makeTableName(stmt->relname, column->colname, "key", NULL);
+ column->constraints = lappend(column->constraints, constraint);
+ }
+
sequence = makeNode(CreateSeqStmt);
sequence->seqname = pstrdup(constraint->name);
sequence->options = NIL;
@@ -543,12 +558,6 @@ transformCreateStmt(ParseState *pstate, CreateStmt *stmt)
sequence->seqname, stmt->relname, column->colname);
ilist = lcons(sequence, NIL);
-
- constraint = makeNode(Constraint);
- constraint->contype = CONSTR_UNIQUE;
- constraint->name = makeTableName(stmt->relname, column->colname, "key", NULL);
-
- column->constraints = lappend(column->constraints, constraint);
}
if (column->constraints != NIL)