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

Commitb4bedfa

Browse files
committed
Tweak SERIAL column creation to emit a fully qualified sequence name
as argument for nextval().
1 parent8860110 commitb4bedfa

File tree

1 file changed

+27
-23
lines changed

1 file changed

+27
-23
lines changed

‎src/backend/parser/analyze.c

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
*$Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.225 2002/03/31 06:26:31 tgl Exp $
9+
*$Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.226 2002/04/02 06:30:34 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -35,6 +35,7 @@
3535
#include"rewrite/rewriteManip.h"
3636
#include"utils/builtins.h"
3737
#include"utils/fmgroids.h"
38+
#include"utils/lsyscache.h"
3839
#include"utils/relcache.h"
3940
#include"utils/syscache.h"
4041
#ifdefMULTIBYTE
@@ -801,25 +802,43 @@ transformColumnDefinition(ParseState *pstate, CreateStmtContext *cxt,
801802
if (is_serial)
802803
{
803804
char*sname;
805+
char*snamespace;
804806
char*qstring;
805807
A_Const*snamenode;
806808
FuncCall*funccallnode;
807-
CreateSeqStmt*sequence;
809+
CreateSeqStmt*seqstmt;
810+
811+
/*
812+
* Determine name and namespace to use for the sequence.
813+
*/
814+
sname=makeObjectName(cxt->relation->relname,column->colname,"seq");
815+
snamespace=get_namespace_name(RangeVarGetCreationNamespace(cxt->relation));
816+
817+
elog(NOTICE,"%s will create implicit sequence '%s' for SERIAL column '%s.%s'",
818+
cxt->stmtType,sname,cxt->relation->relname,column->colname);
819+
820+
/*
821+
* Build a CREATE SEQUENCE command to create the sequence object,
822+
* and add it to the list of things to be done before this
823+
* CREATE/ALTER TABLE.
824+
*/
825+
seqstmt=makeNode(CreateSeqStmt);
826+
seqstmt->sequence=makeRangeVar(snamespace,sname);
827+
seqstmt->options=NIL;
828+
829+
cxt->blist=lappend(cxt->blist,seqstmt);
808830

809831
/*
810832
* Create appropriate constraints for SERIAL. We do this in full,
811833
* rather than shortcutting, so that we will detect any
812834
* conflicting constraints the user wrote (like a different
813835
* DEFAULT).
814-
*/
815-
sname=makeObjectName((cxt->relation)->relname,column->colname,"seq");
816-
817-
/*
836+
*
818837
* Create an expression tree representing the function call
819838
* nextval('"sequencename"')
820839
*/
821-
qstring=palloc(strlen(sname)+2+1);
822-
sprintf(qstring,"\"%s\"",sname);
840+
qstring=palloc(strlen(snamespace)+strlen(sname)+5+1);
841+
sprintf(qstring,"\"%s\".\"%s\"",snamespace,sname);
823842
snamenode=makeNode(A_Const);
824843
snamenode->val.type=T_String;
825844
snamenode->val.val.str=qstring;
@@ -845,21 +864,6 @@ transformColumnDefinition(ParseState *pstate, CreateStmtContext *cxt,
845864
constraint=makeNode(Constraint);
846865
constraint->contype=CONSTR_NOTNULL;
847866
column->constraints=lappend(column->constraints,constraint);
848-
849-
/*
850-
* Build a CREATE SEQUENCE command to create the sequence object,
851-
* and add it to the list of things to be done before this
852-
* CREATE/ALTER TABLE.
853-
*/
854-
sequence=makeNode(CreateSeqStmt);
855-
sequence->sequence=copyObject(cxt->relation);
856-
sequence->sequence->relname=pstrdup(sname);
857-
sequence->options=NIL;
858-
859-
elog(NOTICE,"%s will create implicit sequence '%s' for SERIAL column '%s.%s'",
860-
cxt->stmtType,sequence->sequence->relname, (cxt->relation)->relname,column->colname);
861-
862-
cxt->blist=lappend(cxt->blist,sequence);
863867
}
864868

865869
/* Process column constraints, if any... */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp