diff options
| author | Tom Lane | 2008-05-16 23:36:05 +0000 |
|---|---|---|
| committer | Tom Lane | 2008-05-16 23:36:05 +0000 |
| commit | 10a3471bed7b57fb986a5be8afdee5f0dda419de (patch) | |
| tree | 32de8db702827c67c5cb85479d9bbff22c7b6e94 /src/backend/parser | |
| parent | 8a2f5d221b0d6e41dc66b7e7389668bd208e3529 (diff) | |
Add a RESTART (without parameter) option to ALTER SEQUENCE, allowing a
sequence to be reset to its original starting value. This requires adding the
original start value to the set of parameters (columns) of a sequence object,
which is a user-visible change with potential compatibility implications;
it also forces initdb.
Also add hopefully-SQL-compatible RESTART/CONTINUE IDENTITY options to
TRUNCATE TABLE. RESTART IDENTITY executes ALTER SEQUENCE RESTART for all
sequences "owned by" any of the truncated relations. CONTINUE IDENTITY is
a no-op option.
Zoltan Boszormenyi
Diffstat (limited to 'src/backend/parser')
| -rw-r--r-- | src/backend/parser/gram.y | 31 | ||||
| -rw-r--r-- | src/backend/parser/keywords.c | 4 |
2 files changed, 25 insertions, 10 deletions
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index 56a56627e7f..591920d6f68 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -11,7 +11,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.614 2008/04/29 20:44:49 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.615 2008/05/16 23:36:05 tgl Exp $ * * HISTORY * AUTHOR DATE MAJOR EVENT @@ -206,7 +206,7 @@ static Node *makeXmlExpr(XmlExprOp op, char *name, List *named_args, List *args) %type <str> OptSchemaName %type <list> OptSchemaEltList -%type <boolean> TriggerActionTime TriggerForSpec opt_trusted +%type <boolean> TriggerActionTime TriggerForSpec opt_trusted opt_restart_seqs %type <str> opt_lancompiler %type <str> TriggerEvents @@ -381,7 +381,7 @@ static Node *makeXmlExpr(XmlExprOp op, char *name, List *named_args, List *args) CHARACTER CHARACTERISTICS CHECK CHECKPOINT CLASS CLOSE CLUSTER COALESCE COLLATE COLUMN COMMENT COMMIT COMMITTED CONCURRENTLY CONFIGURATION CONNECTION CONSTRAINT CONSTRAINTS - CONTENT_P CONVERSION_P COPY COST CREATE CREATEDB + CONTENT_P CONTINUE_P CONVERSION_P COPY COST CREATE CREATEDB CREATEROLE CREATEUSER CROSS CSV CURRENT_P CURRENT_DATE CURRENT_ROLE CURRENT_TIME CURRENT_TIMESTAMP CURRENT_USER CURSOR CYCLE @@ -399,10 +399,10 @@ static Node *makeXmlExpr(XmlExprOp op, char *name, List *named_args, List *args) HANDLER HAVING HEADER_P HOLD HOUR_P - IF_P ILIKE IMMEDIATE IMMUTABLE IMPLICIT_P IN_P INCLUDING INCREMENT - INDEX INDEXES INHERIT INHERITS INITIALLY INNER_P INOUT INPUT_P - INSENSITIVE INSERT INSTEAD INT_P INTEGER INTERSECT - INTERVAL INTO INVOKER IS ISNULL ISOLATION + IDENTITY_P IF_P ILIKE IMMEDIATE IMMUTABLE IMPLICIT_P IN_P + INCLUDING INCREMENT INDEX INDEXES INHERIT INHERITS INITIALLY + INNER_P INOUT INPUT_P INSENSITIVE INSERT INSTEAD INT_P INTEGER + INTERSECT INTERVAL INTO INVOKER IS ISNULL ISOLATION JOIN @@ -2489,6 +2489,10 @@ OptSeqElem: CACHE NumericOnly { $$ = makeDefElem("start", (Node *)$3); } + | RESTART + { + $$ = makeDefElem("restart", NULL); + } | RESTART opt_with NumericOnly { $$ = makeDefElem("restart", (Node *)$3); @@ -3364,15 +3368,22 @@ attrs: '.' attr_name *****************************************************************************/ TruncateStmt: - TRUNCATE opt_table qualified_name_list opt_drop_behavior + TRUNCATE opt_table qualified_name_list opt_restart_seqs opt_drop_behavior { TruncateStmt *n = makeNode(TruncateStmt); n->relations = $3; - n->behavior = $4; + n->restart_seqs = $4; + n->behavior = $5; $$ = (Node *)n; } ; +opt_restart_seqs: + CONTINUE_P IDENTITY_P { $$ = false; } + | RESTART IDENTITY_P { $$ = true; } + | /* EMPTY */ { $$ = false; } + ; + /***************************************************************************** * * The COMMENT ON statement can take different forms based upon the type of @@ -8964,6 +8975,7 @@ unreserved_keyword: | CONNECTION | CONSTRAINTS | CONTENT_P + | CONTINUE_P | CONVERSION_P | COPY | COST @@ -9014,6 +9026,7 @@ unreserved_keyword: | HEADER_P | HOLD | HOUR_P + | IDENTITY_P | IF_P | IMMEDIATE | IMMUTABLE diff --git a/src/backend/parser/keywords.c b/src/backend/parser/keywords.c index b5312a487fd..46b306b98d1 100644 --- a/src/backend/parser/keywords.c +++ b/src/backend/parser/keywords.c @@ -11,7 +11,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/parser/keywords.c,v 1.195 2008/03/27 03:57:33 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/parser/keywords.c,v 1.196 2008/05/16 23:36:05 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -101,6 +101,7 @@ static const ScanKeyword ScanKeywords[] = { {"constraint", CONSTRAINT, RESERVED_KEYWORD}, {"constraints", CONSTRAINTS, UNRESERVED_KEYWORD}, {"content", CONTENT_P, UNRESERVED_KEYWORD}, + {"continue", CONTINUE_P, UNRESERVED_KEYWORD}, {"conversion", CONVERSION_P, UNRESERVED_KEYWORD}, {"copy", COPY, UNRESERVED_KEYWORD}, {"cost", COST, UNRESERVED_KEYWORD}, @@ -181,6 +182,7 @@ static const ScanKeyword ScanKeywords[] = { {"header", HEADER_P, UNRESERVED_KEYWORD}, {"hold", HOLD, UNRESERVED_KEYWORD}, {"hour", HOUR_P, UNRESERVED_KEYWORD}, + {"identity", IDENTITY_P, UNRESERVED_KEYWORD}, {"if", IF_P, UNRESERVED_KEYWORD}, {"ilike", ILIKE, TYPE_FUNC_NAME_KEYWORD}, {"immediate", IMMEDIATE, UNRESERVED_KEYWORD}, |
