55 *
66 * Copyright (c) 1994, Regents of the University of California
77 *
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 $
99 *
1010 *-------------------------------------------------------------------------
1111 */
@@ -579,6 +579,9 @@ transformCreateStmt(ParseState *pstate, CreateStmt *stmt)
579579columns = NIL ;
580580dlist = NIL ;
581581
582+ /*
583+ * Run through each primary element in the table creation clause
584+ */
582585while (elements != NIL )
583586{
584587element = lfirst (elements );
@@ -588,6 +591,7 @@ transformCreateStmt(ParseState *pstate, CreateStmt *stmt)
588591column = (ColumnDef * )element ;
589592columns = lappend (columns ,column );
590593
594+ /* Special case SERIAL type? */
591595if (column -> is_sequence )
592596{
593597char * sname ;
@@ -625,6 +629,7 @@ transformCreateStmt(ParseState *pstate, CreateStmt *stmt)
625629blist = lcons (sequence ,NIL );
626630}
627631
632+ /* Check for column constraints, if any... */
628633if (column -> constraints != NIL )
629634{
630635clist = column -> constraints ;
@@ -815,28 +820,43 @@ transformCreateStmt(ParseState *pstate, CreateStmt *stmt)
815820 * or if a SERIAL column was defined along with a table PRIMARY KEY constraint.
816821 * - thomas 1999-05-11
817822 */
818- if (( pkey != NULL ) && ( length ( lfirst ( pkey -> indexParams )) == 1 ) )
823+ if (pkey != NULL )
819824{
820825dlist = ilist ;
821826ilist = NIL ;
822827while (dlist != NIL )
823828{
824- int keep = TRUE;
829+ List * pcols ,* icols ;
830+ int plen ,ilen ;
831+ int keep = TRUE;
825832
826833index = lfirst (dlist );
834+ pcols = pkey -> indexParams ;
835+ icols = index -> indexParams ;
827836
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 ))
834842{
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 ;
837850
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+ }
840860}
841861
842862if (keep )