From a0b012a1ab85ae115f30e5e4fe09922b4885fdad Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sun, 15 Jun 2008 01:25:54 +0000 Subject: Rearrange ALTER TABLE syntax processing as per my recent proposal: the grammar allows ALTER TABLE/INDEX/SEQUENCE/VIEW interchangeably for all subforms of those commands, and then we sort out what's really legal at execution time. This allows the ALTER SEQUENCE/VIEW reference pages to fully document all the ALTER forms available for sequences and views respectively, and eliminates a longstanding cause of confusion for users. The net effect is that the following forms are allowed that weren't before: ALTER SEQUENCE OWNER TO ALTER VIEW ALTER COLUMN SET/DROP DEFAULT ALTER VIEW OWNER TO ALTER VIEW SET SCHEMA (There's no actual functionality gain here, but formerly you had to say ALTER TABLE instead.) Interestingly, the grammar tables actually get smaller, probably because there are fewer special cases to keep track of. I did not disallow using ALTER TABLE for these operations. Perhaps we should, but there's a backwards-compatibility issue if we do; in fact it would break existing pg_dump scripts. I did however tighten up ALTER SEQUENCE and ALTER VIEW to reject non-sequences and non-views in the new cases as well as a couple of cases where they didn't before. The patch doesn't change pg_dump to use the new syntaxes, either. --- src/backend/tcop/utility.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) (limited to 'src/backend/tcop/utility.c') diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c index 6c839650b43..1922ffc960d 100644 --- a/src/backend/tcop/utility.c +++ b/src/backend/tcop/utility.c @@ -10,7 +10,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/tcop/utility.c,v 1.293 2008/06/14 18:04:33 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/tcop/utility.c,v 1.294 2008/06/15 01:25:54 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -1454,6 +1454,9 @@ CreateCommandTag(Node *parsetree) case OBJECT_TSCONFIGURATION: tag = "ALTER TEXT SEARCH CONFIGURATION"; break; + case OBJECT_VIEW: + tag = "ALTER VIEW"; + break; default: tag = "???"; break; @@ -1512,19 +1515,23 @@ CreateCommandTag(Node *parsetree) break; case T_AlterTableStmt: + switch (((AlterTableStmt *) parsetree)->relkind) { - AlterTableStmt *stmt = (AlterTableStmt *) parsetree; - - /* - * We might be supporting ALTER INDEX here, so set the - * completion tag appropriately. Catch all other possibilities - * with ALTER TABLE - */ - - if (stmt->relkind == OBJECT_INDEX) - tag = "ALTER INDEX"; - else + case OBJECT_TABLE: tag = "ALTER TABLE"; + break; + case OBJECT_INDEX: + tag = "ALTER INDEX"; + break; + case OBJECT_SEQUENCE: + tag = "ALTER SEQUENCE"; + break; + case OBJECT_VIEW: + tag = "ALTER VIEW"; + break; + default: + tag = "???"; + break; } break; -- cgit v1.2.3