From a0c6dfeecfcc860858b04617a9d96eaee1d82c66 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Tue, 12 Mar 2013 17:37:07 -0400 Subject: Allow default expressions to be attached to columns of foreign tables. There's still some discussion about exactly how postgres_fdw ought to handle this case, but there seems no debate that we want to allow defaults to be used for inserts into foreign tables. So remove the core-code restrictions that prevented it. While at it, get rid of the special grammar productions for CREATE FOREIGN TABLE, and instead add explicit FEATURE_NOT_SUPPORTED error checks for the disallowed cases. This makes the grammar a shade smaller, and more importantly results in much more intelligible error messages for unsupported cases. It's also one less thing to fix if we ever start supporting constraints on foreign tables. --- doc/src/sgml/ref/alter_foreign_table.sgml | 19 +++++++++++++++++- doc/src/sgml/ref/create_foreign_table.sgml | 31 +++++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 2 deletions(-) (limited to 'doc/src') diff --git a/doc/src/sgml/ref/alter_foreign_table.sgml b/doc/src/sgml/ref/alter_foreign_table.sgml index f0b3129ab09..723aa075c57 100644 --- a/doc/src/sgml/ref/alter_foreign_table.sgml +++ b/doc/src/sgml/ref/alter_foreign_table.sgml @@ -32,9 +32,11 @@ ALTER FOREIGN TABLE [ IF EXISTS ] namewhere action is one of: - ADD [ COLUMN ] column_name data_type [ NULL | NOT NULL ] + ADD [ COLUMN ] column_name data_type [ COLLATE collation ] [ column_constraint [ ... ] ] DROP [ COLUMN ] [ IF EXISTS ] column_name [ RESTRICT | CASCADE ] ALTER [ COLUMN ] column_name [ SET DATA ] TYPE data_type + ALTER [ COLUMN ] column_name SET DEFAULT expression + ALTER [ COLUMN ] column_name DROP DEFAULT ALTER [ COLUMN ] column_name { SET | DROP } NOT NULL ALTER [ COLUMN ] column_name SET STATISTICS integer ALTER [ COLUMN ] column_name SET ( attribute_option = value [, ... ] ) @@ -59,6 +61,9 @@ ALTER FOREIGN TABLE [ IF EXISTS ] name This form adds a new column to the foreign table, using the same syntax as . + Unlike the case when adding a column to a regular table, nothing happens + to the underlying storage: this action simply declares that + some new column is now accessible through the foreign table. @@ -97,6 +102,18 @@ ALTER FOREIGN TABLE [ IF EXISTS ] name + + SET/DROP DEFAULT + + + These forms set or remove the default value for a column. + Default values only apply in subsequent INSERT + or UPDATE commands; they do not cause rows already in the + table to change. + + + + SET/DROP NOT NULL diff --git a/doc/src/sgml/ref/create_foreign_table.sgml b/doc/src/sgml/ref/create_foreign_table.sgml index 0a6ac29d4d9..1ef4b5e9d74 100644 --- a/doc/src/sgml/ref/create_foreign_table.sgml +++ b/doc/src/sgml/ref/create_foreign_table.sgml @@ -19,12 +19,18 @@ CREATE FOREIGN TABLE [ IF NOT EXISTS ] table_name ( [ - { column_name data_type [ OPTIONS ( option 'value' [, ... ] ) ] [ NULL | NOT NULL ] } + column_name data_type [ OPTIONS ( option 'value' [, ... ] ) ] [ COLLATE collation ] [ column_constraint [ ... ] ] [, ... ] ] ) SERVER server_name [ OPTIONS ( option 'value' [, ... ] ) ] +where column_constraint is: + +[ CONSTRAINT constraint_name ] +{ NOT NULL | + NULL | + DEFAULT default_expr } @@ -131,6 +137,27 @@ CREATE FOREIGN TABLE [ IF NOT EXISTS ] table_name + + DEFAULT + default_expr + + + The DEFAULT clause assigns a default data value for + the column whose column definition it appears within. The value + is any variable-free expression (subqueries and cross-references + to other columns in the current table are not allowed). The + data type of the default expression must match the data type of the + column. + + + + The default expression will be used in any insert operation that + does not specify a value for the column. If there is no default + for a column, then the default is null. + + + + server_name @@ -190,6 +217,8 @@ SERVER film_server; SQL standard; however, much as with CREATE TABLE, NULL constraints and zero-column foreign tables are permitted. + The ability to specify a default value is also a PostgreSQL + extension. -- cgit v1.2.3