Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7ff198c

Browse files
author
Thomas G. Lockhart
committed
Support SERIAL column type. Expand column marked is_sequence into three
statements: - the table definition with a default clause referencing the sequence; - a CREATE SEQUENCE statement; - a UNIQUE constraint, which expands into a CREATE INDEX statement.This is not a perfect solution, since the sequence will remain even if the table is dropped. Also, there is no absolute protection on updating the sequence column.
1 parent12cf9f8 commit7ff198c

File tree

1 file changed

+42
-3
lines changed

1 file changed

+42
-3
lines changed

‎src/backend/parser/analyze.c

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.80 1998/08/18 00:48:54 scrappy Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.81 1998/08/25 15:08:12 thomas Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -472,7 +472,7 @@ transformCreateStmt(ParseState *pstate, CreateStmt *stmt)
472472
Constraint*constraint;
473473
List*keys;
474474
Ident*key;
475-
List*ilist;
475+
List*ilist=NIL;
476476
IndexStmt*index;
477477
IndexElem*iparam;
478478

@@ -492,6 +492,46 @@ transformCreateStmt(ParseState *pstate, CreateStmt *stmt)
492492
caseT_ColumnDef:
493493
column= (ColumnDef*)element;
494494
columns=lappend(columns,column);
495+
496+
if (column->is_sequence)
497+
{
498+
char*cstring;
499+
CreateSeqStmt*sequence;
500+
501+
constraint=makeNode(Constraint);
502+
constraint->contype=CONSTR_DEFAULT;
503+
constraint->name=makeTableName(stmt->relname,column->colname,"seq",NULL);
504+
cstring=palloc(9+strlen(constraint->name)+2+1);
505+
strcpy(cstring,"nextval('");
506+
strcat(cstring,constraint->name);
507+
strcat(cstring,"')");
508+
constraint->def=cstring;
509+
constraint->keys=NULL;
510+
511+
if (column->constraints!=NIL)
512+
{
513+
column->constraints=lappend(column->constraints,constraint);
514+
}
515+
else
516+
{
517+
column->constraints=lcons(constraint,NIL);
518+
}
519+
520+
sequence=makeNode(CreateSeqStmt);
521+
sequence->seqname=constraint->name;
522+
sequence->options=NIL;
523+
524+
elog(NOTICE,"CREATE TABLE will create implicit sequence %s for SERIAL column %s.%s",
525+
sequence->seqname,stmt->relname,column->colname);
526+
527+
ilist=lcons(sequence,NIL);
528+
529+
constraint=makeNode(Constraint);
530+
constraint->contype=CONSTR_UNIQUE;
531+
532+
column->constraints=lappend(column->constraints,constraint);
533+
}
534+
495535
if (column->constraints!=NIL)
496536
{
497537
clist=column->constraints;
@@ -596,7 +636,6 @@ transformCreateStmt(ParseState *pstate, CreateStmt *stmt)
596636
*names for indices turn out to be redundant, or a user might have specified
597637
*extra useless indices which might hurt performance. - thomas 1997-12-08
598638
*/
599-
ilist=NIL;
600639
while (dlist!=NIL)
601640
{
602641
constraint=lfirst(dlist);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp