5
5
*
6
6
* Copyright (c) 1994, Regents of the University of California
7
7
*
8
- * $Id: analyze.c,v 1.116 1999/07/19 00:26:18 tgl Exp $
8
+ * $Id: analyze.c,v 1.117 1999/08/15 06:46:49 thomas Exp $
9
9
*
10
10
*-------------------------------------------------------------------------
11
11
*/
@@ -579,6 +579,9 @@ transformCreateStmt(ParseState *pstate, CreateStmt *stmt)
579
579
columns = NIL ;
580
580
dlist = NIL ;
581
581
582
+ /*
583
+ * Run through each primary element in the table creation clause
584
+ */
582
585
while (elements != NIL )
583
586
{
584
587
element = lfirst (elements );
@@ -588,6 +591,7 @@ transformCreateStmt(ParseState *pstate, CreateStmt *stmt)
588
591
column = (ColumnDef * ) element ;
589
592
columns = lappend (columns , column );
590
593
594
+ /* Special case SERIAL type? */
591
595
if (column -> is_sequence )
592
596
{
593
597
char * sname ;
@@ -625,6 +629,7 @@ transformCreateStmt(ParseState *pstate, CreateStmt *stmt)
625
629
blist = lcons (sequence , NIL );
626
630
}
627
631
632
+ /* Check for column constraints, if any... */
628
633
if (column -> constraints != NIL )
629
634
{
630
635
clist = column -> constraints ;
@@ -815,28 +820,43 @@ transformCreateStmt(ParseState *pstate, CreateStmt *stmt)
815
820
* or if a SERIAL column was defined along with a table PRIMARY KEY constraint.
816
821
* - thomas 1999-05-11
817
822
*/
818
- if (( pkey != NULL ) && ( length ( lfirst ( pkey -> indexParams )) == 1 ) )
823
+ if (pkey != NULL )
819
824
{
820
825
dlist = ilist ;
821
826
ilist = NIL ;
822
827
while (dlist != NIL )
823
828
{
824
- int keep = TRUE;
829
+ List * pcols , * icols ;
830
+ int plen , ilen ;
831
+ int keep = TRUE;
825
832
826
833
index = lfirst (dlist );
834
+ pcols = pkey -> indexParams ;
835
+ icols = index -> indexParams ;
827
836
828
- /*
829
- * has a single column argument, so might be a conflicting
830
- * index...
831
- */
832
- if ((index != pkey )
833
- && (length (index -> indexParams ) == 1 ))
837
+ plen = length (pcols );
838
+ ilen = length (icols );
839
+
840
+ /* Not the same as the primary key? Then we should look... */
841
+ if ((index != pkey ) && (ilen == plen ))
834
842
{
835
- char * pname = ((IndexElem * ) lfirst (index -> indexParams ))-> name ;
836
- char * iname = ((IndexElem * ) lfirst (index -> indexParams ))-> name ;
843
+ keep = FALSE;
844
+ while ((pcols != NIL ) && (icols != NIL ))
845
+ {
846
+ IndexElem * pcol = lfirst (pcols );
847
+ IndexElem * icol = lfirst (icols );
848
+ char * pname = pcol -> name ;
849
+ char * iname = icol -> name ;
837
850
838
- /* same names? then don't keep... */
839
- keep = (strcmp (iname , pname ) != 0 );
851
+ /* different names? then no match... */
852
+ if (strcmp (iname , pname ) != 0 )
853
+ {
854
+ keep = TRUE;
855
+ break ;
856
+ }
857
+ pcols = lnext (pcols );
858
+ icols = lnext (icols );
859
+ }
840
860
}
841
861
842
862
if (keep )
0 commit comments