Commit d4f4b971 authored by Tom Lane's avatar Tom Lane

Sequences are now based on int8, not int4, arithmetic. SERIAL pseudo-type

has an alias SERIAL4 and a sister SERIAL8.  SERIAL8 is just the same
except the created column is type int8 not int4.
initdb forced.  Note this also breaks any chance of pg_upgrade from 7.1,
unless we hack up pg_upgrade to drop and recreate sequences.  (Which is
not out of the question, but I don't wanna do it.)
parent bcb0ccf5
......@@ -79,8 +79,13 @@ autoinc(PG_FUNCTION_ARGS)
seqname = DirectFunctionCall1(textin,
CStringGetDatum(args[i]));
newvals[chnattrs] = DirectFunctionCall1(nextval, seqname);
/* nextval now returns int64; coerce down to int32 */
newvals[chnattrs] = Int32GetDatum((int32) DatumGetInt64(newvals[chnattrs]));
if (DatumGetInt32(newvals[chnattrs]) == 0)
{
newvals[chnattrs] = DirectFunctionCall1(nextval, seqname);
newvals[chnattrs] = Int32GetDatum((int32) DatumGetInt64(newvals[chnattrs]));
}
pfree(DatumGetTextP(seqname));
chnattrs++;
i++;
......
<!--
$Header: /cvsroot/pgsql/doc/src/sgml/datatype.sgml,v 1.57 2001/08/07 22:41:49 petere Exp $
$Header: /cvsroot/pgsql/doc/src/sgml/datatype.sgml,v 1.58 2001/08/16 20:38:53 tgl Exp $
-->
<chapter id="datatype">
......@@ -199,10 +199,16 @@ $Header: /cvsroot/pgsql/doc/src/sgml/datatype.sgml,v 1.57 2001/08/07 22:41:49 pe
<row>
<entry><type>serial</type></entry>
<entry></entry>
<entry><type>serial4</type></entry>
<entry>autoincrementing four-byte integer</entry>
</row>
<row>
<entry><type>serial8</type></entry>
<entry></entry>
<entry>autoincrementing eight-byte integer</entry>
</row>
<row>
<entry><type>text</type></entry>
<entry></entry>
......@@ -394,10 +400,17 @@ $Header: /cvsroot/pgsql/doc/src/sgml/datatype.sgml,v 1.57 2001/08/07 22:41:49 pe
</row>
<row>
<entry>serial</entry>
<entry>serial4</entry>
<entry>4 bytes</entry>
<entry>Identifier or cross-reference</entry>
<entry>0 to +2147483647</entry>
<entry>1 to 2147483647</entry>
</row>
<row>
<entry>serial8</entry>
<entry>8 bytes</entry>
<entry>Identifier or cross-reference</entry>
<entry>1 to 9223372036854775807</entry>
</row>
</tbody>
</tgroup>
......@@ -413,17 +426,27 @@ $Header: /cvsroot/pgsql/doc/src/sgml/datatype.sgml,v 1.57 2001/08/07 22:41:49 pe
</para>
<para>
The <type>bigint</type> type may not be available on all platforms since
it relies on compiler support for eight-byte integers.
The <type>bigint</type> type may not function correctly on all platforms,
since it relies on compiler support for eight-byte integers. On a machine
without such support, <type>bigint</type> acts the same
as <type>integer</type> (but still takes up eight bytes of storage).
</para>
<sect2 id="datatype-serial">
<title>The Serial Type</title>
<title>The Serial Types</title>
<indexterm zone="datatype-serial">
<primary>serial</primary>
</indexterm>
<indexterm zone="datatype-serial">
<primary>serial4</primary>
</indexterm>
<indexterm zone="datatype-serial">
<primary>serial8</primary>
</indexterm>
<indexterm>
<primary>auto-increment</primary>
<see>serial</see>
......@@ -435,9 +458,9 @@ $Header: /cvsroot/pgsql/doc/src/sgml/datatype.sgml,v 1.57 2001/08/07 22:41:49 pe
</indexterm>
<para>
The <type>serial</type> type is a special-case type constructed by
<productname>Postgres</productname> from other existing components.
It is typically used to create unique identifiers for table entries.
The <type>serial</type> datatypes are not truly types, but are a
notational convenience for setting up unique identifier columns
in tables.
In the current implementation, specifying
<programlisting>
......@@ -449,10 +472,14 @@ CREATE TABLE <replaceable class="parameter">tablename</replaceable> (<replaceabl
<programlisting>
CREATE SEQUENCE <replaceable class="parameter">tablename</replaceable>_<replaceable class="parameter">colname</replaceable>_seq;
CREATE TABLE <replaceable class="parameter">tablename</replaceable>
(<replaceable class="parameter">colname</replaceable> integer DEFAULT nextval('<replaceable class="parameter">tablename</replaceable>_<replaceable class="parameter">colname</replaceable>_seq');
CREATE UNIQUE INDEX <replaceable class="parameter">tablename</replaceable>_<replaceable class="parameter">colname</replaceable>_key on <replaceable class="parameter">tablename</replaceable> (<replaceable class="parameter">colname</replaceable>);
(<replaceable class="parameter">colname</replaceable> integer DEFAULT nextval('<replaceable class="parameter">tablename</replaceable>_<replaceable class="parameter">colname</replaceable>_seq') UNIQUE NOT NULL;
</programlisting>
Thus, we have created an integer column and arranged for its default
values to be assigned from a sequence generator. UNIQUE and NOT NULL
constraints are applied to ensure that explicitly-inserted values
will never be duplicates, either.
<caution>
<para>
The implicit sequence created for the <type>serial</type> type will
......@@ -460,7 +487,18 @@ CREATE UNIQUE INDEX <replaceable class="parameter">tablename</replaceable>_<repl
table is dropped.
</para>
</caution>
</para>
<para>
The type names <type>serial</type> and <type>serial4</type> are
equivalent: both create <type>integer</type> columns. The type
name <type>serial8</type> works just the same way, except that it
creates a <type>bigint</type> column. <type>serial8</type> should
be used if you anticipate use of more than 2^31 identifiers over
the lifetime of the table.
</para>
<para>
Implicit sequences supporting the <type>serial</type> are
not automatically dropped when a table containing a serial type
is dropped. So, the following commands executed in order will likely fail:
......
<!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_sequence.sgml,v 1.17 2001/06/30 22:01:17 petere Exp $
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_sequence.sgml,v 1.18 2001/08/16 20:38:53 tgl Exp $
Postgres documentation
-->
......@@ -79,7 +79,7 @@ CREATE [ TEMPORARY | TEMP ] SEQUENCE <replaceable class="parameter">seqname</rep
The optional clause <option>MINVALUE
<replaceable class="parameter">minvalue</replaceable></option>
determines the minimum value
a sequence can generate. The defaults are 1 and -2147483647 for
a sequence can generate. The defaults are 1 and -2^63-1 for
ascending and descending sequences, respectively.
</para>
</listitem>
......@@ -92,7 +92,7 @@ CREATE [ TEMPORARY | TEMP ] SEQUENCE <replaceable class="parameter">seqname</rep
The optional clause <option>MAXVALUE
<replaceable class="parameter">maxvalue</replaceable></option>
determines the maximum
value for the sequence. The defaults are 2147483647 and -1 for
value for the sequence. The defaults are 2^63-1 and -1 for
ascending and descending sequences, respectively.
</para>
</listitem>
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/creatinh.c,v 1.79 2001/08/10 18:57:34 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/creatinh.c,v 1.80 2001/08/16 20:38:53 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -447,7 +447,6 @@ MergeAttributes(List *schema, List *supers, bool istemp,
typename->typmod = attribute->atttypmod;
def->typename = typename;
def->is_not_null = attribute->attnotnull;
def->is_sequence = false;
def->raw_default = NULL;
def->cooked_default = NULL;
def->constraints = NIL;
......
This diff is collapsed.
......@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: view.c,v 1.56 2001/08/12 21:35:18 tgl Exp $
* $Id: view.c,v 1.57 2001/08/16 20:38:53 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -68,7 +68,6 @@ DefineVirtualRelation(char *relname, List *tlist)
def->typename = typename;
def->is_not_null = false;
def->is_sequence = false;
def->raw_default = NULL;
def->cooked_default = NULL;
def->constraints = NIL;
......
......@@ -15,7 +15,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.152 2001/08/10 18:57:36 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.153 2001/08/16 20:38:53 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -1708,7 +1708,6 @@ _copyColumnDef(ColumnDef *from)
newnode->colname = pstrdup(from->colname);
Node_Copy(from, newnode, typename);
newnode->is_not_null = from->is_not_null;
newnode->is_sequence = from->is_sequence;
Node_Copy(from, newnode, raw_default);
if (from->cooked_default)
newnode->cooked_default = pstrdup(from->cooked_default);
......
......@@ -20,7 +20,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.100 2001/08/10 18:57:36 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.101 2001/08/16 20:38:53 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -1543,8 +1543,6 @@ _equalColumnDef(ColumnDef *a, ColumnDef *b)
return false;
if (a->is_not_null != b->is_not_null)
return false;
if (a->is_sequence != b->is_sequence)
return false;
if (!equal(a->raw_default, b->raw_default))
return false;
if (!equalstr(a->cooked_default, b->cooked_default))
......
......@@ -5,7 +5,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/nodes/outfuncs.c,v 1.143 2001/08/10 18:57:36 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/nodes/outfuncs.c,v 1.144 2001/08/16 20:38:53 tgl Exp $
*
* NOTES
* Every (plan) node in POSTGRES has an associated "out" routine which
......@@ -175,9 +175,8 @@ _outColumnDef(StringInfo str, ColumnDef *node)
_outToken(str, node->colname);
appendStringInfo(str, " :typename ");
_outNode(str, node->typename);
appendStringInfo(str, " :is_not_null %s :is_sequence %s :raw_default ",
booltostr(node->is_not_null),
booltostr(node->is_sequence));
appendStringInfo(str, " :is_not_null %s :raw_default ",
booltostr(node->is_not_null));
_outNode(str, node->raw_default);
appendStringInfo(str, " :cooked_default ");
_outToken(str, node->cooked_default);
......
......@@ -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.194 2001/08/11 00:02:13 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.195 2001/08/16 20:38:53 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -702,6 +702,7 @@ transformCreateStmt(ParseState *pstate, CreateStmt *stmt)
*pkey = NULL;
IndexElem *iparam;
bool saw_nullable;
bool is_serial;
q = makeNode(Query);
q->commandType = CMD_UTILITY;
......@@ -723,10 +724,25 @@ transformCreateStmt(ParseState *pstate, CreateStmt *stmt)
column = (ColumnDef *) element;
columns = lappend(columns, column);
/* Check for SERIAL pseudo-types */
is_serial = false;
if (strcmp(column->typename->name, "serial") == 0 ||
strcmp(column->typename->name, "serial4") == 0)
{
is_serial = true;
column->typename->name = pstrdup("int4");
}
else if (strcmp(column->typename->name, "serial8") == 0)
{
is_serial = true;
column->typename->name = pstrdup("int8");
}
/* Do necessary work on the column type declaration */
transformColumnType(pstate, column);
/* Special case SERIAL type? */
if (column->is_sequence)
/* Special actions for SERIAL pseudo-types */
if (is_serial)
{
char *sname;
char *qstring;
......@@ -778,13 +794,18 @@ transformCreateStmt(ParseState *pstate, CreateStmt *stmt)
column->constraints = lappend(column->constraints,
constraint);
/*
* Build a CREATE SEQUENCE command to create the
* sequence object, and add it to the list of things
* to be done before this CREATE TABLE.
*/
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'",
sequence->seqname, stmt->relname, column->colname);
sequence->seqname, stmt->relname, column->colname);
blist = lappend(blist, sequence);
}
......
......@@ -11,7 +11,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.245 2001/08/15 18:42:15 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.246 2001/08/16 20:38:53 tgl Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
......@@ -354,7 +354,7 @@ static void doNegateFloat(Value *v);
NEW, NOCREATEDB, NOCREATEUSER, NONE, NOTHING, NOTIFY, NOTNULL,
OFFSET, OIDS, OPERATOR, OWNER, PASSWORD, PROCEDURAL,
REINDEX, RENAME, RESET, RETURNS, ROW, RULE,
SEQUENCE, SERIAL, SETOF, SHARE, SHOW, START, STATEMENT,
SEQUENCE, SETOF, SHARE, SHOW, START, STATEMENT,
STATISTICS, STDIN, STDOUT, SYSID,
TEMP, TEMPLATE, TOAST, TRUNCATE, TRUSTED,
UNLISTEN, UNTIL, VACUUM, VALID, VERBOSE, VERSION
......@@ -1249,22 +1249,6 @@ columnDef: ColId Typename ColQualList opt_collate
n->typename = $2;
n->constraints = $3;
if ($4 != NULL)
elog(NOTICE,"CREATE TABLE/COLLATE %s not yet implemented"
"; clause ignored", $4);
$$ = (Node *)n;
}
| ColId SERIAL ColQualList opt_collate
{
ColumnDef *n = makeNode(ColumnDef);
n->colname = $1;
n->typename = makeNode(TypeName);
n->typename->name = xlateSqlType("integer");
n->typename->typmod = -1;
n->is_sequence = TRUE;
n->constraints = $3;
if ($4 != NULL)
elog(NOTICE,"CREATE TABLE/COLLATE %s not yet implemented"
"; clause ignored", $4);
......@@ -1630,7 +1614,7 @@ OptSeqList: OptSeqList OptSeqElem
| { $$ = NIL; }
;
OptSeqElem: CACHE IntegerOnly
OptSeqElem: CACHE NumericOnly
{
$$ = makeNode(DefElem);
$$->defname = "cache";
......@@ -1642,25 +1626,25 @@ OptSeqElem: CACHE IntegerOnly
$$->defname = "cycle";
$$->arg = (Node *)NULL;
}
| INCREMENT IntegerOnly
| INCREMENT NumericOnly
{
$$ = makeNode(DefElem);
$$->defname = "increment";
$$->arg = (Node *)$2;
}
| MAXVALUE IntegerOnly
| MAXVALUE NumericOnly
{
$$ = makeNode(DefElem);
$$->defname = "maxvalue";
$$->arg = (Node *)$2;
}
| MINVALUE IntegerOnly
| MINVALUE NumericOnly
{
$$ = makeNode(DefElem);
$$->defname = "minvalue";
$$->arg = (Node *)$2;
}
| START IntegerOnly
| START NumericOnly
{
$$ = makeNode(DefElem);
$$->defname = "start";
......@@ -5593,7 +5577,6 @@ ColId: IDENT { $$ = $1; }
| NATIONAL { $$ = "national"; }
| NONE { $$ = "none"; }
| PATH_P { $$ = "path"; }
| SERIAL { $$ = "serial"; }
| TIME { $$ = "time"; }
| TIMESTAMP { $$ = "timestamp"; }
;
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.95 2001/08/15 18:42:15 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.96 2001/08/16 20:38:54 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -228,7 +228,6 @@ static ScanKeyword ScanKeywords[] = {
{"second", SECOND_P},
{"select", SELECT},
{"sequence", SEQUENCE},
{"serial", SERIAL},
{"serializable", SERIALIZABLE},
{"session", SESSION},
{"session_user", SESSION_USER},
......
......@@ -22,7 +22,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.221 2001/08/12 19:02:39 petere Exp $
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.222 2001/08/16 20:38:54 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -4019,6 +4019,8 @@ dumpTables(Archive *fout, TableInfo *tblinfo, int numTables,
/* First - dump SEQUENCEs */
if (tablename && strlen(tablename) > 0)
{
/* XXX this code only works for serial columns named "id" */
/* We really need dependency analysis! */
serialSeq = malloc(strlen(tablename) + strlen(serialSeqSuffix) + 1);
strcpy(serialSeq, tablename);
strcat(serialSeq, serialSeqSuffix);
......@@ -4036,7 +4038,7 @@ dumpTables(Archive *fout, TableInfo *tblinfo, int numTables,
dumpACL(fout, tblinfo[i]);
}
}
if (tablename)
if (serialSeq)
free(serialSeq);
for (i = 0; i < numTables; i++)
......@@ -4737,14 +4739,13 @@ static void
dumpSequence(Archive *fout, TableInfo tbinfo, const bool schemaOnly, const bool dataOnly)
{
PGresult *res;
int4 last,
incby,
maxv,
minv,
cache;
char cycled,
char *last,
*incby,
*maxv,
*minv,
*cache;
bool cycled,
called;
const char *t;
PQExpBuffer query = createPQExpBuffer();
PQExpBuffer delqry = createPQExpBuffer();
......@@ -4774,20 +4775,18 @@ dumpSequence(Archive *fout, TableInfo tbinfo, const bool schemaOnly, const bool
exit_nicely();
}
last = atoi(PQgetvalue(res, 0, 1));
incby = atoi(PQgetvalue(res, 0, 2));
maxv = atoi(PQgetvalue(res, 0, 3));
minv = atoi(PQgetvalue(res, 0, 4));
cache = atoi(PQgetvalue(res, 0, 5));
t = PQgetvalue(res, 0, 6);
cycled = *t;
t = PQgetvalue(res, 0, 7);
called = *t;
last = PQgetvalue(res, 0, 1);
incby = PQgetvalue(res, 0, 2);
maxv = PQgetvalue(res, 0, 3);
minv = PQgetvalue(res, 0, 4);
cache = PQgetvalue(res, 0, 5);
cycled = (strcmp(PQgetvalue(res, 0, 6), "t") == 0);
called = (strcmp(PQgetvalue(res, 0, 7), "t") == 0);
/*
* The logic we use for restoring sequences is as follows: - Add a
* basic CREATE SEQUENCE statement (use last_val for start if called
* with 'f', else use min_val for start_val).
* is false, else use min_val for start_val).
*
* Add a 'SETVAL(seq, last_val, iscalled)' at restore-time iff
* we load data
......@@ -4795,22 +4794,22 @@ dumpSequence(Archive *fout, TableInfo tbinfo, const bool schemaOnly, const bool
if (!dataOnly)
{
PQclear(res);
resetPQExpBuffer(delqry);
appendPQExpBuffer(delqry, "DROP SEQUENCE %s;\n", fmtId(tbinfo.relname, force_quotes));
appendPQExpBuffer(delqry, "DROP SEQUENCE %s;\n",
fmtId(tbinfo.relname, force_quotes));
resetPQExpBuffer(query);
appendPQExpBuffer(query,
"CREATE SEQUENCE %s start %d increment %d maxvalue %d "
"minvalue %d cache %d %s;\n",
"CREATE SEQUENCE %s start %s increment %s "
"maxvalue %s minvalue %s cache %s%s;\n",
fmtId(tbinfo.relname, force_quotes),
(called == 't') ? minv : last,
(called ? minv : last),
incby, maxv, minv, cache,
(cycled == 't') ? "cycle" : "");
(cycled ? " cycle" : ""));
ArchiveEntry(fout, tbinfo.oid, tbinfo.relname, "SEQUENCE", NULL,
query->data, delqry->data, "", tbinfo.usename, NULL, NULL);
query->data, delqry->data, "", tbinfo.usename,
NULL, NULL);
}
if (!schemaOnly)
......@@ -4818,7 +4817,8 @@ dumpSequence(Archive *fout, TableInfo tbinfo, const bool schemaOnly, const bool
resetPQExpBuffer(query);
appendPQExpBuffer(query, "SELECT setval (");
formatStringLiteral(query, fmtId(tbinfo.relname, force_quotes), CONV_ALL);
appendPQExpBuffer(query, ", %d, '%c');\n", last, called);
appendPQExpBuffer(query, ", %s, %s);\n",
last, (called ? "true" : "false"));
ArchiveEntry(fout, tbinfo.oid, tbinfo.relname, "SEQUENCE SET", NULL,
query->data, "" /* Del */ , "", "", NULL, NULL);
......@@ -4834,6 +4834,8 @@ dumpSequence(Archive *fout, TableInfo tbinfo, const bool schemaOnly, const bool
"pg_class", 0, NULL);
}
PQclear(res);
destroyPQExpBuffer(query);
destroyPQExpBuffer(delqry);
}
......
......@@ -37,7 +37,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: catversion.h,v 1.89 2001/08/14 22:21:58 tgl Exp $
* $Id: catversion.h,v 1.90 2001/08/16 20:38:54 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -53,6 +53,6 @@
*/
/* yyyymmddN */
#define CATALOG_VERSION_NO 200108132
#define CATALOG_VERSION_NO 200108151
#endif
......@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: pg_proc.h,v 1.205 2001/08/15 07:07:40 ishii Exp $
* $Id: pg_proc.h,v 1.206 2001/08/16 20:38:54 tgl Exp $
*
* NOTES
* The script catalog/genbki.sh reads this file and generates .bki
......@@ -2003,13 +2003,13 @@ DESCR("convert int8 to int8 (no-op)");
/* SEQUENCEs nextval & currval functions */
DATA(insert OID = 1574 ( nextval PGUID 12 f t f t 1 f 23 "25" 100 0 0 100 nextval - ));
DATA(insert OID = 1574 ( nextval PGUID 12 f t f t 1 f 20 "25" 100 0 0 100 nextval - ));
DESCR("sequence next value");
DATA(insert OID = 1575 ( currval PGUID 12 f t f t 1 f 23 "25" 100 0 0 100 currval - ));
DATA(insert OID = 1575 ( currval PGUID 12 f t f t 1 f 20 "25" 100 0 0 100 currval - ));
DESCR("sequence current value");
DATA(insert OID = 1576 ( setval PGUID 12 f t f t 2 f 23 "25 23" 100 0 0 100 setval - ));
DATA(insert OID = 1576 ( setval PGUID 12 f t f t 2 f 20 "25 20" 100 0 0 100 setval - ));
DESCR("set sequence value");
DATA(insert OID = 1765 ( setval PGUID 12 f t f t 3 f 23 "25 23 16" 100 0 0 100 setval_and_iscalled - ));
DATA(insert OID = 1765 ( setval PGUID 12 f t f t 3 f 20 "25 20 16" 100 0 0 100 setval_and_iscalled - ));
DESCR("set sequence value and iscalled status");
DATA(insert OID = 1579 ( varbit_in PGUID 12 f t t t 1 f 1562 "0" 100 0 0 100 varbit_in - ));
......
......@@ -3,6 +3,10 @@
* sequence.h
* prototypes for sequence.c.
*
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: sequence.h,v 1.16 2001/08/16 20:38:55 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -12,17 +16,38 @@
#include "nodes/parsenodes.h"
#include "access/xlog.h"
/*
* On a machine with no 64-bit-int C datatype, sizeof(int64) will not be 8,
* but we need this struct type to line up with the way that a sequence
* table is defined --- and pg_type will say that int8 is 8 bytes anyway.
* So, we need padding. Ugly but necessary.
*/
typedef struct FormData_pg_sequence
{
NameData sequence_name;
#ifndef INT64_IS_BUSTED
int64 last_value;
int64 increment_by;
int64 max_value;
int64 min_value;
int64 cache_value;
int64 log_cnt;
#else
int32 last_value;
int32 pad1;
int32 increment_by;
int32 pad2;
int32 max_value;
int32 pad3;
int32 min_value;
int32 pad4;
int32 cache_value;
int32 pad5;
int32 log_cnt;
char is_cycled;
char is_called;
int32 pad6;
#endif
bool is_cycled;
bool is_called;
} FormData_pg_sequence;
typedef FormData_pg_sequence *Form_pg_sequence;
......
......@@ -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.140 2001/08/10 18:57:41 tgl Exp $
* $Id: parsenodes.h,v 1.141 2001/08/16 20:38:55 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -1097,8 +1097,7 @@ typedef struct ColumnDef
NodeTag type;
char *colname; /* name of column */
TypeName *typename; /* type of column */
bool is_not_null; /* flag to NOT NULL constraint */
bool is_sequence; /* is a sequence? */
bool is_not_null; /* NOT NULL constraint specified? */
Node *raw_default; /* default value (untransformed parse
* tree) */
char *cooked_default; /* nodeToString representation */
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/keywords.c,v 1.42 2001/07/16 05:07:00 tgl Exp $
* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/keywords.c,v 1.43 2001/08/16 20:38:55 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -227,7 +227,6 @@ static ScanKeyword ScanKeywords[] = {
{"second", SECOND_P},
{"select", SELECT},
{"sequence", SEQUENCE},
{"serial", SERIAL},
{"serializable", SERIALIZABLE},
{"session", SESSION},
{"session_user", SESSION_USER},
......
......@@ -223,7 +223,7 @@ make_name(void)
MINVALUE, MODE, MOVE, NEW, NOCREATEDB, NOCREATEUSER,
NONE, NOTHING, NOTIFY, NOTNULL, OFFSET, OIDS,
OPERATOR, OWNER, PASSWORD, PROCEDURAL, REINDEX, RENAME, RESET,
RETURNS, ROW, RULE, SEQUENCE, SERIAL, SETOF, SHARE,
RETURNS, ROW, RULE, SEQUENCE, SETOF, SHARE,
SHOW, START, STATEMENT, STATISTICS, STDIN, STDOUT, SYSID TEMP,
TEMPLATE, TOAST, TRUNCATE, TRUSTED, UNLISTEN, UNTIL, VACUUM,
VALID, VERBOSE, VERSION
......@@ -1107,15 +1107,6 @@ columnDef: ColId Typename ColQualList opt_collate
}
$$ = cat_str(4, $1, $2, $3, $4);
}
| ColId SERIAL ColQualList opt_collate
{
if (strlen($4) > 0)
{
sprintf(errortext, "CREATE TABLE/COLLATE %s not yet implemented; clause ignored", $4);
mmerror(ET_NOTICE, errortext);
}
$$ = cat_str(4, $1, make_str(" serial "), $3, $4);
}
;
ColQualList: ColQualList ColConstraint { $$ = cat2_str($1,$2); }
......@@ -5106,7 +5097,6 @@ ECPGColId: ident { $$ = $1; }
| NATIONAL { $$ = make_str("national"); }
| NONE { $$ = make_str("none"); }
| PATH_P { $$ = make_str("path_p"); }
| SERIAL { $$ = make_str("serial"); }
| TIME { $$ = make_str("time"); }
| TIMESTAMP { $$ = make_str("timestamp"); }
| ECPGKeywords { $$ = $1; }
......
......@@ -1317,10 +1317,10 @@ SELECT tablename, rulename, definition FROM pg_rules
rtest_nothn1 | rtest_nothn_r2 | CREATE RULE rtest_nothn_r2 AS ON INSERT TO rtest_nothn1 WHERE ((new.a >= 30) AND (new.a < 40)) DO INSTEAD NOTHING;
rtest_nothn2 | rtest_nothn_r3 | CREATE RULE rtest_nothn_r3 AS ON INSERT TO rtest_nothn2 WHERE (new.a >= 100) DO INSTEAD INSERT INTO rtest_nothn3 (a, b) VALUES (new.a, new.b);
rtest_nothn2 | rtest_nothn_r4 | CREATE RULE rtest_nothn_r4 AS ON INSERT TO rtest_nothn2 DO INSTEAD NOTHING;
rtest_order1 | rtest_order_r1 | CREATE RULE rtest_order_r1 AS ON INSERT TO rtest_order1 DO INSTEAD INSERT INTO rtest_order2 (a, b, c) VALUES (new.a, nextval('rtest_seq'::text), 'rule 1 - this should run 3rd or 4th'::text);
rtest_order1 | rtest_order_r2 | CREATE RULE rtest_order_r2 AS ON INSERT TO rtest_order1 DO INSERT INTO rtest_order2 (a, b, c) VALUES (new.a, nextval('rtest_seq'::text), 'rule 2 - this should run 1st'::text);
rtest_order1 | rtest_order_r3 | CREATE RULE rtest_order_r3 AS ON INSERT TO rtest_order1 DO INSTEAD INSERT INTO rtest_order2 (a, b, c) VALUES (new.a, nextval('rtest_seq'::text), 'rule 3 - this should run 3rd or 4th'::text);
rtest_order1 | rtest_order_r4 | CREATE RULE rtest_order_r4 AS ON INSERT TO rtest_order1 WHERE (new.a < 100) DO INSTEAD INSERT INTO rtest_order2 (a, b, c) VALUES (new.a, nextval('rtest_seq'::text), 'rule 4 - this should run 2nd'::text);
rtest_order1 | rtest_order_r1 | CREATE RULE rtest_order_r1 AS ON INSERT TO rtest_order1 DO INSTEAD INSERT INTO rtest_order2 (a, b, c) VALUES (new.a, int4(nextval('rtest_seq'::text)), 'rule 1 - this should run 3rd or 4th'::text);
rtest_order1 | rtest_order_r2 | CREATE RULE rtest_order_r2 AS ON INSERT TO rtest_order1 DO INSERT INTO rtest_order2 (a, b, c) VALUES (new.a, int4(nextval('rtest_seq'::text)), 'rule 2 - this should run 1st'::text);
rtest_order1 | rtest_order_r3 | CREATE RULE rtest_order_r3 AS ON INSERT TO rtest_order1 DO INSTEAD INSERT INTO rtest_order2 (a, b, c) VALUES (new.a, int4(nextval('rtest_seq'::text)), 'rule 3 - this should run 3rd or 4th'::text);
rtest_order1 | rtest_order_r4 | CREATE RULE rtest_order_r4 AS ON INSERT TO rtest_order1 WHERE (new.a < 100) DO INSTEAD INSERT INTO rtest_order2 (a, b, c) VALUES (new.a, int4(nextval('rtest_seq'::text)), 'rule 4 - this should run 2nd'::text);
rtest_person | rtest_pers_del | CREATE RULE rtest_pers_del AS ON DELETE TO rtest_person DO DELETE FROM rtest_admin WHERE (rtest_admin.pname = old.pname);
rtest_person | rtest_pers_upd | CREATE RULE rtest_pers_upd AS ON UPDATE TO rtest_person DO UPDATE rtest_admin SET pname = new.pname WHERE (rtest_admin.pname = old.pname);
rtest_system | rtest_sys_del | CREATE RULE rtest_sys_del AS ON DELETE TO rtest_system DO (DELETE FROM rtest_interface WHERE (rtest_interface.sysname = old.sysname); DELETE FROM rtest_admin WHERE (rtest_admin.sysname = old.sysname); );
......
/*
* $Header: /cvsroot/pgsql/src/test/regress/regress.c,v 1.47 2001/03/22 04:01:44 momjian Exp $
* $Header: /cvsroot/pgsql/src/test/regress/regress.c,v 1.48 2001/08/16 20:38:56 tgl Exp $
*/
#include "postgres.h"
......@@ -565,6 +565,8 @@ ttdummy(PG_FUNCTION_ARGS)
newoff = DirectFunctionCall1(nextval,
PointerGetDatum(seqname));
/* nextval now returns int64; coerce down to int32 */
newoff = Int32GetDatum((int32) DatumGetInt64(newoff));
pfree(seqname);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment