|
6 | 6 | * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
7 | 7 | * Portions Copyright (c) 1994, Regents of the University of California
|
8 | 8 | *
|
9 |
| - * $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.191 2001/06/25 21:11:44 tgl Exp $ |
| 9 | + * $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.192 2001/07/04 17:36:54 tgl Exp $ |
10 | 10 | *
|
11 | 11 | *-------------------------------------------------------------------------
|
12 | 12 | */
|
@@ -954,8 +954,8 @@ transformCreateStmt(ParseState *pstate, CreateStmt *stmt)
|
954 | 954 |
|
955 | 955 | index = makeNode(IndexStmt);
|
956 | 956 |
|
957 |
| - index->unique = TRUE; |
958 |
| - index->primary = (constraint->contype == CONSTR_PRIMARY ? TRUE : FALSE); |
| 957 | + index->unique = true; |
| 958 | + index->primary = (constraint->contype == CONSTR_PRIMARY); |
959 | 959 | if (index->primary)
|
960 | 960 | {
|
961 | 961 | if (pkey != NULL)
|
@@ -1057,6 +1057,17 @@ transformCreateStmt(ParseState *pstate, CreateStmt *stmt)
|
1057 | 1057 | elog(ERROR, "CREATE TABLE: column \"%s\" named in key does not exist",
|
1058 | 1058 | key->name);
|
1059 | 1059 |
|
| 1060 | + /* Check for PRIMARY KEY(foo, foo) */ |
| 1061 | + foreach(columns, index->indexParams) |
| 1062 | + { |
| 1063 | + iparam = (IndexElem *) lfirst(columns); |
| 1064 | + if (strcmp(key->name, iparam->name) == 0) |
| 1065 | + elog(ERROR, "CREATE TABLE: column \"%s\" appears twice in %s constraint", |
| 1066 | + key->name, |
| 1067 | + index->primary ? "PRIMARY KEY" : "UNIQUE"); |
| 1068 | + } |
| 1069 | + |
| 1070 | + /* OK, add it to the index definition */ |
1060 | 1071 | iparam = makeNode(IndexElem);
|
1061 | 1072 | iparam->name = pstrdup(key->name);
|
1062 | 1073 | iparam->args = NIL;
|
|
0 commit comments