From a0c12d5e905fdea19cf529af4f2d76e74412abc8 Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Sat, 23 Jun 2001 00:07:34 +0000 Subject: [PATCH] Add TEMPORARY sequences and have SERIAL on a temp table have a temporary sequence. --- doc/src/sgml/ref/create_sequence.sgml | 17 +++++++++++++++-- src/backend/commands/sequence.c | 3 ++- src/backend/parser/analyze.c | 5 +++-- src/backend/parser/gram.y | 9 +++++---- src/include/nodes/parsenodes.h | 3 ++- src/interfaces/ecpg/preproc/preproc.y | 4 ++-- 6 files changed, 29 insertions(+), 12 deletions(-) diff --git a/doc/src/sgml/ref/create_sequence.sgml b/doc/src/sgml/ref/create_sequence.sgml index 718037785c..f6a2614f36 100644 --- a/doc/src/sgml/ref/create_sequence.sgml +++ b/doc/src/sgml/ref/create_sequence.sgml @@ -1,5 +1,5 @@ @@ -23,7 +23,7 @@ Postgres documentation 1999-07-20 -CREATE SEQUENCE seqname [ INCREMENT increment ] +CREATE [ TEMPORARY | TEMP ] SEQUENCE seqname [ INCREMENT increment ] [ MINVALUE minvalue ] [ MAXVALUE maxvalue ] [ START start ] [ CACHE cache ] [ CYCLE ] @@ -37,6 +37,19 @@ CREATE SEQUENCE seqname [ INCREMENT + + + TEMPORARY or TEMP + + + If specified, the sequence is created only for this session, and is + automatically dropped on session exit. + Existing permanent sequences with the same name are not visible + (in this session) while the temporary sequence exists. + + + + seqname diff --git a/src/backend/commands/sequence.c b/src/backend/commands/sequence.c index 6861ee5c3d..400c60b9b4 100644 --- a/src/backend/commands/sequence.c +++ b/src/backend/commands/sequence.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/sequence.c,v 1.59 2001/06/13 21:07:12 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/sequence.c,v 1.60 2001/06/23 00:07:34 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -161,6 +161,7 @@ DefineSequence(CreateSeqStmt *seq) } stmt->relname = seq->seqname; + stmt->istemp = seq->istemp; stmt->inhRelnames = NIL; stmt->constraints = NIL; diff --git a/src/backend/parser/analyze.c b/src/backend/parser/analyze.c index c6f21e77b0..c0280c7b88 100644 --- a/src/backend/parser/analyze.c +++ b/src/backend/parser/analyze.c @@ -6,7 +6,7 @@ * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.189 2001/06/04 23:27:23 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.190 2001/06/23 00:07:34 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -779,6 +779,7 @@ transformCreateStmt(ParseState *pstate, CreateStmt *stmt) sequence = makeNode(CreateSeqStmt); sequence->seqname = pstrdup(sname); + sequence->istemp = stmt->istemp; sequence->options = NIL; elog(NOTICE, "CREATE TABLE will create implicit sequence '%s' for SERIAL column '%s.%s'", @@ -2716,7 +2717,7 @@ transformAlterTableStmt(ParseState *pstate, AlterTableStmt *stmt) return qry; } -/* +/* * Transform uses of %TYPE in a statement. */ static Node * diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index e47c3f0b33..3c7d526a7b 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -11,7 +11,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.231 2001/06/19 22:39:11 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.232 2001/06/23 00:07:34 momjian Exp $ * * HISTORY * AUTHOR DATE MAJOR EVENT @@ -1574,11 +1574,12 @@ CreateAsElement: ColId * *****************************************************************************/ -CreateSeqStmt: CREATE SEQUENCE relation_name OptSeqList +CreateSeqStmt: CREATE OptTemp SEQUENCE relation_name OptSeqList { CreateSeqStmt *n = makeNode(CreateSeqStmt); - n->seqname = $3; - n->options = $4; + n->istemp = $2; + n->seqname = $4; + n->options = $5; $$ = (Node *)n; } ; diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h index 43e64b6ad5..42b72e8074 100644 --- a/src/include/nodes/parsenodes.h +++ b/src/include/nodes/parsenodes.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $Id: parsenodes.h,v 1.132 2001/06/19 22:39:12 tgl Exp $ + * $Id: parsenodes.h,v 1.133 2001/06/23 00:07:34 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -402,6 +402,7 @@ typedef struct CreateSeqStmt { NodeTag type; char *seqname; /* the relation to create */ + bool istemp; /* is this a temp sequence? */ List *options; } CreateSeqStmt; diff --git a/src/interfaces/ecpg/preproc/preproc.y b/src/interfaces/ecpg/preproc/preproc.y index c0b6c9c097..2228c125d8 100644 --- a/src/interfaces/ecpg/preproc/preproc.y +++ b/src/interfaces/ecpg/preproc/preproc.y @@ -1289,9 +1289,9 @@ CreateAsElement: ColId { $$ = $1; } * *****************************************************************************/ -CreateSeqStmt: CREATE SEQUENCE relation_name OptSeqList +CreateSeqStmt: CREATE OptTemp SEQUENCE relation_name OptSeqList { - $$ = cat_str(3, make_str("create sequence"), $3, $4); + $$ = cat_str(4, make_str("create sequence"), $2, $4, $5); } ;