Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 9bbc165

Browse files
author
Thomas G. Lockhart
committed
Add double quotes around the sequence name generated to support the
SERIAL data type DEFAULT clause. This fixes a problem finding the sequence name when mixed case table names are involved.
1 parent 81c83db commit 9bbc165

File tree

1 file changed

+18
-45
lines changed

1 file changed

+18
-45
lines changed

src/backend/parser/analyze.c

Lines changed: 18 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* Copyright (c) 1994, Regents of the University of California
77
*
8-
* $Id: analyze.c,v 1.103 1999/05/13 07:28:34 tgl Exp $
8+
* $Id: analyze.c,v 1.104 1999/05/13 15:01:32 thomas Exp $
99
*
1010
*-------------------------------------------------------------------------
1111
*/
@@ -546,39 +546,22 @@ transformCreateStmt(ParseState *pstate, CreateStmt *stmt)
546546
constraint->contype = CONSTR_DEFAULT;
547547
constraint->name = sname;
548548
cstring = palloc(9 + strlen(constraint->name) + 2 + 1);
549-
strcpy(cstring, "nextval('");
549+
strcpy(cstring, "nextval('\"");
550550
strcat(cstring, constraint->name);
551-
strcat(cstring, "')");
551+
strcat(cstring, "\"')");
552552
constraint->def = cstring;
553553
constraint->keys = NULL;
554554

555-
#if 0
556-
/* The parser only allows PRIMARY KEY as a constraint for the SERIAL type.
557-
* So, if there is a constraint of any kind, assume it is that.
558-
* If PRIMARY KEY is specified, then don't need to gin up a UNIQUE constraint
559-
* since that will be covered already.
560-
* - thomas 1998-09-15
561-
*/
562-
if (column->constraints != NIL)
563-
{
564-
column->constraints = lappend(column->constraints, constraint);
565-
}
566-
else
567-
{
568-
#endif
569-
column->constraints = lappend(column->constraints, constraint);
555+
column->constraints = lappend(column->constraints, constraint);
570556

571-
constraint = makeNode(Constraint);
572-
constraint->contype = CONSTR_UNIQUE;
573-
constraint->name = makeTableName(stmt->relname, column->colname, "key", NULL);
574-
if (constraint->name == NULL)
575-
elog(ERROR, "CREATE TABLE/SERIAL implicit index name must be less than %d characters"
576-
"\n\tSum of lengths of '%s' and '%s' must be less than %d",
577-
NAMEDATALEN, stmt->relname, column->colname, (NAMEDATALEN-5));
578-
column->constraints = lappend(column->constraints, constraint);
579-
#if 0
580-
}
581-
#endif
557+
constraint = makeNode(Constraint);
558+
constraint->contype = CONSTR_UNIQUE;
559+
constraint->name = makeTableName(stmt->relname, column->colname, "key", NULL);
560+
if (constraint->name == NULL)
561+
elog(ERROR, "CREATE TABLE/SERIAL implicit index name must be less than %d characters"
562+
"\n\tSum of lengths of '%s' and '%s' must be less than %d",
563+
NAMEDATALEN, stmt->relname, column->colname, (NAMEDATALEN-5));
564+
column->constraints = lappend(column->constraints, constraint);
582565

583566
sequence = makeNode(CreateSeqStmt);
584567
sequence->seqname = pstrdup(sname);
@@ -604,21 +587,21 @@ transformCreateStmt(ParseState *pstate, CreateStmt *stmt)
604587
*/
605588
if (column->is_not_null)
606589
elog(ERROR, "CREATE TABLE/(NOT) NULL conflicting declaration"
607-
" for %s.%s", stmt->relname, column->colname);
590+
" for '%s.%s'", stmt->relname, column->colname);
608591
column->is_not_null = FALSE;
609592
break;
610593

611594
case CONSTR_NOTNULL:
612595
if (column->is_not_null)
613596
elog(ERROR, "CREATE TABLE/NOT NULL already specified"
614-
" for %s.%s", stmt->relname, column->colname);
597+
" for '%s.%s'", stmt->relname, column->colname);
615598
column->is_not_null = TRUE;
616599
break;
617600

618601
case CONSTR_DEFAULT:
619602
if (column->defval != NULL)
620603
elog(ERROR, "CREATE TABLE/DEFAULT multiple values specified"
621-
" for %s.%s", stmt->relname, column->colname);
604+
" for '%s.%s'", stmt->relname, column->colname);
622605
column->defval = constraint->def;
623606
break;
624607

@@ -680,10 +663,6 @@ transformCreateStmt(ParseState *pstate, CreateStmt *stmt)
680663
break;
681664

682665
case CONSTR_UNIQUE:
683-
#ifdef NOT_USED
684-
if (constraint->name == NULL)
685-
constraint->name = makeTableName(stmt->relname, "key", NULL);
686-
#endif
687666
dlist = lappend(dlist, constraint);
688667
break;
689668

@@ -735,7 +714,7 @@ transformCreateStmt(ParseState *pstate, CreateStmt *stmt)
735714
{
736715
if (pkey != NULL)
737716
elog(ERROR, "CREATE TABLE/PRIMARY KEY multiple primary keys"
738-
" for table %s are not legal", stmt->relname);
717+
" for table '%s' are not allowed", stmt->relname);
739718
pkey = (IndexStmt *) index;
740719
}
741720

@@ -796,14 +775,8 @@ transformCreateStmt(ParseState *pstate, CreateStmt *stmt)
796775
}
797776

798777
if (index->idxname == NULL)
799-
elog(ERROR, "CREATE TABLE unable to construct implicit index for table %s"
778+
elog(ERROR, "CREATE TABLE unable to construct implicit index for table '%s'"
800779
"; name too long", stmt->relname);
801-
#if 0
802-
else
803-
elog(NOTICE, "CREATE TABLE/%s will create implicit index '%s' for table '%s'",
804-
((constraint->contype == CONSTR_PRIMARY) ? "PRIMARY KEY" : "UNIQUE"),
805-
index->idxname, stmt->relname);
806-
#endif
807780

808781
ilist = lappend(ilist, index);
809782
dlist = lnext(dlist);
@@ -855,7 +828,7 @@ transformCreateStmt(ParseState *pstate, CreateStmt *stmt)
855828
extras_after = ilist;
856829

857830
return q;
858-
}
831+
} /* transformCreateStmt() */
859832

860833
/*
861834
* transformIndexStmt -

0 commit comments

Comments
 (0)