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. --- doc/src/sgml/ref/alter_sequence.sgml | 31 +++++++++++----- doc/src/sgml/ref/alter_view.sgml | 68 +++++++++++++++++++++++++++++------- 2 files changed, 79 insertions(+), 20 deletions(-) (limited to 'doc/src/sgml/ref') diff --git a/doc/src/sgml/ref/alter_sequence.sgml b/doc/src/sgml/ref/alter_sequence.sgml index 7cf69e9ea3f..739f3ec0f84 100644 --- a/doc/src/sgml/ref/alter_sequence.sgml +++ b/doc/src/sgml/ref/alter_sequence.sgml @@ -1,5 +1,5 @@ @@ -30,6 +30,7 @@ ALTER SEQUENCE name [ INCREMENT [ B [ RESTART [ [ WITH ] restart ] ] [ CACHE cache ] [ [ NO ] CYCLE ] [ OWNED BY { table.column | NONE } ] +ALTER SEQUENCE name OWNER TO new_owner ALTER SEQUENCE name RENAME TO new_name ALTER SEQUENCE name SET SCHEMA new_schema @@ -48,6 +49,11 @@ ALTER SEQUENCE name SET SCHEMA ALTER SEQUENCE. To change a sequence's schema, you must also have CREATE privilege on the new schema. + To alter the owner, you must also be a direct or indirect member of the new + owning role, and that role must have CREATE privilege on + the sequence's schema. (These restrictions enforce that altering the owner + doesn't do anything you couldn't do by dropping and recreating the sequence. + However, a superuser can alter ownership of any sequence anyway.) @@ -205,6 +211,15 @@ ALTER SEQUENCE name SET SCHEMA + + new_owner + + + The user name of the new owner of the sequence. + + + + new_name @@ -233,9 +248,9 @@ ALTER SEQUENCE name SET SCHEMA To avoid blocking of concurrent transactions that obtain numbers from the same sequence, ALTER SEQUENCE's effects on the sequence - generation parameters are never rolled back; - those changes take effect immediately and are not reversible. However, - the OWNED BY, RENAME, and SET SCHEMA + generation parameters are never rolled back; those changes take effect + immediately and are not reversible. However, the OWNED BY, + OWNER TO, RENAME TO, and SET SCHEMA clauses cause ordinary catalog updates that can be rolled back. @@ -255,9 +270,9 @@ ALTER SEQUENCE name SET SCHEMA - Some variants of ALTER TABLE can be used with - sequences as well; for example, to rename a sequence it is also - possible to use ALTER TABLE RENAME. + For historical reasons, ALTER TABLE can be used with + sequences too; but the only variants of ALTER TABLE + that are allowed with sequences are equivalent to the forms shown above. @@ -278,7 +293,7 @@ ALTER SEQUENCE serial RESTART WITH 105; ALTER SEQUENCE conforms to the SQL standard, except for the START WITH, - OWNED BY, RENAME, and + OWNED BY, OWNER TO, RENAME TO, and SET SCHEMA clauses, which are PostgreSQL extensions. diff --git a/doc/src/sgml/ref/alter_view.sgml b/doc/src/sgml/ref/alter_view.sgml index 7dd052cc124..4c3d9a2479f 100644 --- a/doc/src/sgml/ref/alter_view.sgml +++ b/doc/src/sgml/ref/alter_view.sgml @@ -1,5 +1,5 @@ @@ -20,7 +20,11 @@ PostgreSQL documentation -ALTER VIEW name RENAME TO newname +ALTER VIEW name ALTER [ COLUMN ] column SET DEFAULT expression +ALTER VIEW name ALTER [ COLUMN ] column DROP DEFAULT +ALTER VIEW name OWNER TO new_owner +ALTER VIEW name RENAME TO new_name +ALTER VIEW name SET SCHEMA new_schema @@ -28,9 +32,20 @@ ALTER VIEW name RENAME TO newnameDescription - ALTER VIEW changes the definition of a view. - The only currently available functionality is to rename the view. - To execute this command you must be the owner of the view. + ALTER VIEW changes various auxiliary properties + of a view. (If you want to modify the view's defining query, + use CREATE OR REPLACE VIEW.) + + + + You must own the view to use ALTER VIEW. + To change a view's schema, you must also have CREATE + privilege on the new schema. + To alter the owner, you must also be a direct or indirect member of the new + owning role, and that role must have CREATE privilege on + the view's schema. (These restrictions enforce that altering the owner + doesn't do anything you couldn't do by dropping and recreating the view. + However, a superuser can alter ownership of any view anyway.) @@ -48,10 +63,41 @@ ALTER VIEW name RENAME TO newname - newname + SET/DROP DEFAULT + + + These forms set or remove the default value for a column. + A default value associated with a view column is + inserted into INSERT statements on the view before + the view's ON INSERT rule is applied, if + the INSERT does not specify a value for the column. + + + + + + new_owner + + + The user name of the new owner of the view. + + + + + + new_name + + + The new name for the view. + + + + + + new_schema - The new name of the view. + The new schema for the view. @@ -62,11 +108,9 @@ ALTER VIEW name RENAME TO newnameNotes - Some variants of ALTER TABLE can be used with - views as well; for example, to rename a view it is also - possible to use ALTER TABLE RENAME. To change - the schema or owner of a view, you currently must use ALTER - TABLE. + For historical reasons, ALTER TABLE can be used with + views too; but the only variants of ALTER TABLE + that are allowed with views are equivalent to the ones shown above. -- cgit v1.2.3