]> granicus.if.org Git - postgresql/commitdiff
Support specifying PRIMARY KEY for the SERIAL type.
authorThomas G. Lockhart <lockhart@fourpalms.org>
Wed, 16 Sep 1998 14:25:37 +0000 (14:25 +0000)
committerThomas G. Lockhart <lockhart@fourpalms.org>
Wed, 16 Sep 1998 14:25:37 +0000 (14:25 +0000)
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.

src/backend/parser/analyze.c

index 2d2ab42014511fdb299ab81da9c21dbfab4717fe..dc29f347cf4f3c1033d3fc5ef600652e15b6120b 100644 (file)
@@ -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)