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

Commit a0c12d5

Browse files
committed
Add TEMPORARY sequences and have SERIAL on a temp table have a temporary
sequence.
1 parent 280b5f4 commit a0c12d5

File tree

6 files changed

+29
-12
lines changed

6 files changed

+29
-12
lines changed

doc/src/sgml/ref/create_sequence.sgml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_sequence.sgml,v 1.15 2000/12/08 20:06:58 tgl Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_sequence.sgml,v 1.16 2001/06/23 00:07:33 momjian Exp $
33
Postgres documentation
44
-->
55

@@ -23,7 +23,7 @@ Postgres documentation
2323
<date>1999-07-20</date>
2424
</refsynopsisdivinfo>
2525
<synopsis>
26-
CREATE SEQUENCE <replaceable class="parameter">seqname</replaceable> [ INCREMENT <replaceable class="parameter">increment</replaceable> ]
26+
CREATE [ TEMPORARY | TEMP ] SEQUENCE <replaceable class="parameter">seqname</replaceable> [ INCREMENT <replaceable class="parameter">increment</replaceable> ]
2727
[ MINVALUE <replaceable class="parameter">minvalue</replaceable> ] [ MAXVALUE <replaceable class="parameter">maxvalue</replaceable> ]
2828
[ START <replaceable class="parameter">start</replaceable> ] [ CACHE <replaceable class="parameter">cache</replaceable> ] [ CYCLE ]
2929
</synopsis>
@@ -37,6 +37,19 @@ CREATE SEQUENCE <replaceable class="parameter">seqname</replaceable> [ INCREMENT
3737
</title>
3838
<para>
3939

40+
<variablelist>
41+
<varlistentry>
42+
<term>TEMPORARY or TEMP</term>
43+
<listitem>
44+
<para>
45+
If specified, the sequence is created only for this session, and is
46+
automatically dropped on session exit.
47+
Existing permanent sequences with the same name are not visible
48+
(in this session) while the temporary sequence exists.
49+
</para>
50+
</listitem>
51+
</varlistentry>
52+
4053
<variablelist>
4154
<varlistentry>
4255
<term><replaceable class="parameter">seqname</replaceable></term>

src/backend/commands/sequence.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/commands/sequence.c,v 1.59 2001/06/13 21:07:12 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/commands/sequence.c,v 1.60 2001/06/23 00:07:34 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -161,6 +161,7 @@ DefineSequence(CreateSeqStmt *seq)
161161
}
162162

163163
stmt->relname = seq->seqname;
164+
stmt->istemp = seq->istemp;
164165
stmt->inhRelnames = NIL;
165166
stmt->constraints = NIL;
166167

src/backend/parser/analyze.c

Lines changed: 3 additions & 2 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.189 2001/06/04 23:27:23 momjian Exp $
9+
* $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.190 2001/06/23 00:07:34 momjian Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -779,6 +779,7 @@ transformCreateStmt(ParseState *pstate, CreateStmt *stmt)
779779

780780
sequence = makeNode(CreateSeqStmt);
781781
sequence->seqname = pstrdup(sname);
782+
sequence->istemp = stmt->istemp;
782783
sequence->options = NIL;
783784

784785
elog(NOTICE, "CREATE TABLE will create implicit sequence '%s' for SERIAL column '%s.%s'",
@@ -2716,7 +2717,7 @@ transformAlterTableStmt(ParseState *pstate, AlterTableStmt *stmt)
27162717
return qry;
27172718
}
27182719

2719-
/*
2720+
/*
27202721
* Transform uses of %TYPE in a statement.
27212722
*/
27222723
static Node *

src/backend/parser/gram.y

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.231 2001/06/19 22:39:11 tgl Exp $
14+
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.232 2001/06/23 00:07:34 momjian Exp $
1515
*
1616
* HISTORY
1717
* AUTHOR DATE MAJOR EVENT
@@ -1574,11 +1574,12 @@ CreateAsElement: ColId
15741574
*
15751575
*****************************************************************************/
15761576

1577-
CreateSeqStmt: CREATE SEQUENCE relation_name OptSeqList
1577+
CreateSeqStmt: CREATE OptTemp SEQUENCE relation_name OptSeqList
15781578
{
15791579
CreateSeqStmt *n = makeNode(CreateSeqStmt);
1580-
n->seqname = $3;
1581-
n->options = $4;
1580+
n->istemp = $2;
1581+
n->seqname = $4;
1582+
n->options = $5;
15821583
$$ = (Node *)n;
15831584
}
15841585
;

src/include/nodes/parsenodes.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: parsenodes.h,v 1.132 2001/06/19 22:39:12 tgl Exp $
10+
* $Id: parsenodes.h,v 1.133 2001/06/23 00:07:34 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -402,6 +402,7 @@ typedef struct CreateSeqStmt
402402
{
403403
NodeTag type;
404404
char *seqname; /* the relation to create */
405+
bool istemp; /* is this a temp sequence? */
405406
List *options;
406407
} CreateSeqStmt;
407408

src/interfaces/ecpg/preproc/preproc.y

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,9 +1289,9 @@ CreateAsElement: ColId { $$ = $1; }
12891289
*
12901290
*****************************************************************************/
12911291

1292-
CreateSeqStmt: CREATE SEQUENCE relation_name OptSeqList
1292+
CreateSeqStmt: CREATE OptTemp SEQUENCE relation_name OptSeqList
12931293
{
1294-
$$ = cat_str(3, make_str("create sequence"), $3, $4);
1294+
$$ = cat_str(4, make_str("create sequence"), $2, $4, $5);
12951295
}
12961296
;
12971297

0 commit comments

Comments
 (0)