diff --git a/contrib/pageinspect/rawpage.c b/contrib/pageinspect/rawpage.c index f341a72..822a31f 100644 *** a/contrib/pageinspect/rawpage.c --- b/contrib/pageinspect/rawpage.c *************** get_raw_page_internal(text *relname, For *** 119,124 **** --- 119,129 ---- (errcode(ERRCODE_WRONG_OBJECT_TYPE), errmsg("cannot get raw page from composite type \"%s\"", RelationGetRelationName(rel)))); + if (rel->rd_rel->relkind == RELKIND_FOREIGN_TABLE) + ereport(ERROR, + (errcode(ERRCODE_WRONG_OBJECT_TYPE), + errmsg("cannot get raw page from foreign table \"%s\"", + RelationGetRelationName(rel)))); /* * Reject attempts to read non-local temporary relations; we would be diff --git a/contrib/pgstattuple/pgstattuple.c b/contrib/pgstattuple/pgstattuple.c index 3a5d9c2..e5ddd87 100644 *** a/contrib/pgstattuple/pgstattuple.c --- b/contrib/pgstattuple/pgstattuple.c *************** pgstat_relation(Relation rel, FunctionCa *** 242,247 **** --- 242,250 ---- case RELKIND_COMPOSITE_TYPE: err = "composite type"; break; + case RELKIND_FOREIGN_TABLE: + err = "foreign table"; + break; default: err = "unknown"; break; diff --git a/doc/src/sgml/catalogs.sgml b/doc/src/sgml/catalogs.sgml index 54a6dcc..50ee399 100644 *** a/doc/src/sgml/catalogs.sgml --- b/doc/src/sgml/catalogs.sgml *************** *** 149,154 **** --- 149,159 ---- + pg_foreign_table + additional foreign table information + + + pg_index additional index information *************** *** 1645,1652 **** r = ordinary table, i = index, S = sequence, v = view, c = ! composite type, t = TOAST ! table --- 1650,1657 ---- r = ordinary table, i = index, S = sequence, v = view, c = ! composite type, t = TOAST table, ! f = foiregn table *************** *** 2807,2812 **** --- 2812,2828 ---- + fdwhandler + oid + pg_proc.oid + + References a handler function that is responsible for + supplying foreign-data wrapper routines. + Zero if no handler is provided. + + + + fdwacl aclitem[] *************** *** 2921,2926 **** --- 2937,2997 ---- + + <structname>pg_foreign_table</structname> + + + pg_foreign_table + + + + The catalog pg_foreign_table contains part + of the information about foreign tables. + The rest is mostly in pg_class. + + + + <structname>pg_foreign_table</> Columns + + + + + Name + Type + References + Description + + + + + + ftrelid + oid + pg_class.oid + The OID of the pg_class entry for this foreign table + + + + ftserver + oid + pg_foreign_server.oid + The OID of the foreign server for this foreign table + + + + srvoptions + text[] + + + Foreign table specific options, as keyword=value strings. + + + + +
+
+ + <structname>pg_index</structname> diff --git a/doc/src/sgml/information_schema.sgml b/doc/src/sgml/information_schema.sgml index 9d30949..43305ad 100644 *** a/doc/src/sgml/information_schema.sgml --- b/doc/src/sgml/information_schema.sgml *************** ORDER BY c.ordinal_position; *** 2384,2389 **** --- 2384,2578 ---- + + <literal>foreign_table_options</literal> + + + The view foreign_table_options contains all the + options defined for foreign tables in the current database. Only + those foreign tables are shown that the current user has access to + (by way of being the owner or having some privilege). + + + + <literal>foreign_table_options</literal> Columns + + + + + Name + Data Type + Description + + + + + + foreign_table_catalog + sql_identifier + Name of the database that contains the foreign table (always the current database) + + + + foreign_table_schema + sql_identifier + Name of the schema that contains the foreign table + + + + foreign_table_name + sql_identifier + Name of the foreign table + + + + foreign_server_catalog + sql_identifier + Name of the database that the foreign server is defined in (always the current database) + + + + foreign_server_name + sql_identifier + Name of the foreign server + + + + option_name + sql_identifier + Name of an option + + + + option_value + character_data + Value of the option + + + +
+
+ + + <literal>column_options</literal> + + + The view column_options contains all the generic + options defined for colunms in the current database. + Only those columns are shown that the current user has + access to (by way of being the owner or having some privilege). + + + + <literal>column_options</literal> Columns + + + + + Name + Data Type + Description + + + + + + table_catalog + sql_identifier + Name of the database that contains the table (always the current database) + + + + table_schema + sql_identifier + Name of the schema that contains the table + + + + table_name + sql_identifier + Name of the table + + + + column_name + sql_identifier + Name of the column + + + + option_name + sql_identifier + Name of an option + + + + option_value + character_data + Value of the option + + + +
+
+ + + <literal>foreign_tables</literal> + + + The view foreign_tables contains all foreign + tables defined in the current database. Only those foreign + tables are shown that the current user has access to (by way of + being the owner or having some privilege). + + + + <literal>foreign_tables</literal> Columns + + + + + Name + Data Type + Description + + + + + + foreign_table_catalog + sql_identifier + Name of the database that the foreign table is defined in (always the current database) + + + + foreign_table_schema + sql_identifier + Name of the schema that contains the foreign table + + + + foreign_table_name + sql_identifier + Name of the foreign table + + + + foreign_server_catalog + sql_identifier + Name of the database that the foreign server is defined in (always the current database) + + + + foreign_server_name + sql_identifier + Name of the foreign server + + + +
+
+ <literal>key_column_usage</literal> *************** ORDER BY c.ordinal_position; *** 4730,4737 **** Type of the table: BASE TABLE for a persistent base table (the normal table type), ! VIEW for a view, or LOCAL ! TEMPORARY for a temporary table
--- 4919,4927 ---- Type of the table: BASE TABLE for a persistent base table (the normal table type), ! VIEW for a view, FOREIGN TABLE ! for a foreign table, or ! LOCAL TEMPORARY for a temporary table diff --git a/doc/src/sgml/ref/allfiles.sgml b/doc/src/sgml/ref/allfiles.sgml index a352a43..f40fa9d 100644 *** a/doc/src/sgml/ref/allfiles.sgml --- b/doc/src/sgml/ref/allfiles.sgml *************** Complete list of usable sgml source file *** 12,17 **** --- 12,18 ---- + *************** Complete list of usable sgml source file *** 50,55 **** --- 51,57 ---- + *************** Complete list of usable sgml source file *** 85,90 **** --- 87,93 ---- + diff --git a/doc/src/sgml/ref/alter_default_privileges.sgml b/doc/src/sgml/ref/alter_default_privileges.sgml index e1aa293..612645d 100644 *** a/doc/src/sgml/ref/alter_default_privileges.sgml --- b/doc/src/sgml/ref/alter_default_privileges.sgml *************** REVOKE [ GRANT OPTION FOR ] *** 71,78 **** ALTER DEFAULT PRIVILEGES allows you to set the privileges that will be applied to objects created in the future. (It does not affect privileges assigned to already-existing objects.) Currently, ! only the privileges for tables (including views), sequences, and ! functions can be altered. --- 71,78 ---- ALTER DEFAULT PRIVILEGES allows you to set the privileges that will be applied to objects created in the future. (It does not affect privileges assigned to already-existing objects.) Currently, ! only the privileges for tables (including views and foreign tables), ! sequences, and functions can be altered. diff --git a/doc/src/sgml/ref/alter_foreign_data_wrapper.sgml b/doc/src/sgml/ref/alter_foreign_data_wrapper.sgml index 4e9e8a2..ead2c2e 100644 *** a/doc/src/sgml/ref/alter_foreign_data_wrapper.sgml --- b/doc/src/sgml/ref/alter_foreign_data_wrapper.sgml *************** PostgreSQL documentation *** 23,28 **** --- 23,29 ---- ALTER FOREIGN DATA WRAPPER name [ VALIDATOR valfunction | NO VALIDATOR ] + [ HANDLER handler | NO HANDLER ] [ OPTIONS ( [ ADD | SET | DROP ] option ['value'] [, ... ]) ] ALTER FOREIGN DATA WRAPPER name OWNER TO new_owner *************** ALTER FOREIGN DATA WRAPPER + HANDLER handler + + + Specifies a new foreign-data wrapper handler function. + + + + + + NO HANDLER + + + This is used to specify that the foreign-data wrapper should no + longer have a handler function. + + + Note that foreign tables which uses a foreign-data wrapper with no + handler can't be used in a SELECT statement. + + + + + OPTIONS ( [ ADD | SET | DROP ] option ['value'] [, ... ] ) *************** ALTER FOREIGN DATA WRAPPER dbi VALIDATOR *** 127,134 **** ALTER FOREIGN DATA WRAPPER conforms to ISO/IEC 9075-9 (SQL/MED). The standard does not specify the ! VALIDATOR and OWNER TO variants of the ! command. --- 151,158 ---- ALTER FOREIGN DATA WRAPPER conforms to ISO/IEC 9075-9 (SQL/MED). The standard does not specify the ! VALIDATOR, HANDLER and OWNER TO ! variants of the command. diff --git a/doc/src/sgml/ref/alter_foreign_table.sgml b/doc/src/sgml/ref/alter_foreign_table.sgml index ...ebb3d40 . *** a/doc/src/sgml/ref/alter_foreign_table.sgml --- b/doc/src/sgml/ref/alter_foreign_table.sgml *************** *** 0 **** --- 1,536 ---- + + + + + ALTER FOREIGN TABLE + 7 + SQL - Language Statements + + + + ALTER FOREIGN TABLE + change the definition of a foreign table + + + + ALTER FOREIGN TABLE + + + + + ALTER FOREIGN TABLE name [ * ] + action [, ... ] + ALTER FOREIGN TABLE name [ * ] + RENAME [ COLUMN ] column TO new_column + ALTER FOREIGN TABLE name + RENAME TO new_name + ALTER FOREIGN TABLE name + SET SCHEMA new_schema + + where action is one of: + + ADD [ COLUMN ] column type [ column_constraint [ ... ] ] + DROP [ COLUMN ] [ IF EXISTS ] column [ RESTRICT | CASCADE ] + ALTER [ COLUMN ] column [ SET DATA ] TYPE type + ALTER [ COLUMN ] column SET DEFAULT expression + ALTER [ COLUMN ] column DROP DEFAULT + ALTER [ COLUMN ] column { SET | DROP } NOT NULL + ALTER [ COLUMN ] column OPTIONS ( [ ADD | SET | DROP ] option ['value'] [, ... ]) + ADD table_constraint + DROP CONSTRAINT [ IF EXISTS ] constraint_name [ RESTRICT | CASCADE ] + DISABLE RULE rewrite_rule_name + ENABLE RULE rewrite_rule_name + ENABLE REPLICA RULE rewrite_rule_name + ENABLE ALWAYS RULE rewrite_rule_name + INHERIT parent_table + NO INHERIT parent_table + OWNER TO new_owner + OPTIONS ( [ ADD | SET | DROP ] option ['value'] [, ... ]) + + + + + Description + + + ALTER FOREIGN TABLE changes the definition of an existing table. + There are several subforms: + + + + ADD COLUMN + + + This form adds a new column to the foreign table, using the same syntax as + . + + + + + + DROP COLUMN [ IF EXISTS ] + + + This form drops a column from a foreign table. + Table constraints involving the column will be automatically + dropped as well. You will need to say CASCADE if + anything outside the table depends on the column, for example, + views. + If IF EXISTS is specified and the column + does not exist, no error is thrown. In this case a notice + is issued instead. + + + + + + SET DATA TYPE + + + This form changes the type of a column of a foreign table. + Simple table constraints involving the column will be automatically + converted to use the new column type by reparsing the originally + supplied expression. The optional USING + clause specifies how to compute the new column value from the old; + if omitted, the default conversion is the same as an assignment + cast from old data type to new. A USING + clause must be provided if there is no implicit or assignment + cast from old to new type. + + + + + + SET/DROP NOT NULL + + + These forms change whether a column is marked to allow null + values or to reject null values. You can only use SET + NOT NULL when the column contains no null values. + + + + + + ADD table_constraint + + + This form adds a new constraint to a foreign table using the same syntax as + . + + + + + + DROP CONSTRAINT [ IF EXISTS ] + + + This form drops the specified constraint on a foreign table. + If IF EXISTS is specified and the constraint + does not exist, no error is thrown. In this case a notice is issued instead. + + + + + + DISABLE/ENABLE [ REPLICA | ALWAYS ] RULE + + + These forms configure the firing of rewrite rules belonging to the table. + A disabled rule is still known to the system, but is not applied + during query rewriting. + This configuration is ignored for ON SELECT rules, which + are always applied in order to keep views working even if the current + session is in a non-default replication role. + + + + + + INHERIT parent_table + + + This form adds the target table as a new child of the specified parent + table. Subsequently, queries against the parent will include records + of the target table. To be added as a child, the target table must + already contain all the same columns as the parent (it could have + additional columns, too). The columns must have matching data types, + and if they have NOT NULL constraints in the parent + then they must also have NOT NULL constraints in the + child. + + + + There must also be matching child-table constraints for all + CHECK constraints of the parent. + + + + The parent must not have OIDs because foreign table can't have OIDs. + + + + + + NO INHERIT parent_table + + + This form removes the target table from the list of children of the + specified parent table. + Queries against the parent table will no longer include records drawn + from the target table. + + + + + + OWNER + + + This form changes the owner of the foreign table to the + specified user. + + + + + + RENAME + + + The RENAME forms change the name of a foreign table + or the name of an individual column in + a foreign table. There is no effect on the stored data. + + + + + + SET SCHEMA + + + This form moves the foreign table into another schema. Associated + constraints owned by table columns are moved as well. + + + + + + OPTIONS ( [ ADD | SET | DROP ] option ['value'] [, ... ] ) + + + Change options for the foreign table or the column of the foreign table. + ADD, SET, and DROP + specify the action to be performed. ADD is assumed + if no operation is explicitly specified. Option names must be + unique; names and values are also validated using the foreign + data wrapper library. + + + + + + + + + All the actions except RENAME and SET SCHEMA + can be combined into + a list of multiple alterations to apply in parallel. For example, it + is possible to add several columns and/or alter the type of several + columns in a single command. This is particularly useful with large + foreign tables, since only one pass over the table need be made. + + + + You must own the table to use ALTER FOREIGN TABLE. + To change the schema of a foreign table, you must also have + CREATE privilege on the new schema. + To add the table as a new child of a parent table, you must own the + parent table as well. + 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 table's schema. (These restrictions enforce that altering the owner + doesn't do anything you couldn't do by dropping and recreating the table. + However, a superuser can alter ownership of any table anyway.) + + + + + Parameters + + + + + name + + + The name (possibly schema-qualified) of an existing table to + alter. If ONLY is specified, only that table is + altered. If ONLY is not specified, the table and any + descendant foreign tables are altered. + + + + + + column + + + Name of a new or existing column. + + + + + + new_column + + + New name for an existing column. + + + + + + new_name + + + New name for the table. + + + + + + type + + + Data type of the new column, or new data type for an existing + column. + + + + + + table_constraint + + + New table constraint for the table. + + + + + + constraint_name + + + Name of an existing constraint to drop. + + + + + + CASCADE + + + Automatically drop objects that depend on the dropped column + or constraint (for example, views referencing the column). + + + + + + RESTRICT + + + Refuse to drop the column or constraint if there are any dependent + objects. This is the default behavior. + + + + + + storage_parameter + + + The name of a foreign table storage parameter. + + + + + + value + + + The new value for a foreign table storage parameter. + This might be a number or a word depending on the parameter. + + + + + + parent_table + + + A parent table to associate or de-associate with this table. + + + + + + new_owner + + + The user name of the new owner of the table. + + + + + + new_schema + + + The name of the schema to which the table will be moved. + + + + + + + + + Notes + + + The key word COLUMN is noise and can be omitted. + + + + Consistency with the foreign server is not checked even when a column is + added or removed with ADD COLUMN or + DROP COLUMN, a system oid column is added + or removed, a CHECK or NOT NULL constraint is + added, or column type is changed with ALTER TYPE. + + + + Refer to for a further description of valid + parameters. has further information on + inheritance. + + + + + Examples + + + To add a column of type varchar to a foreign table: + + ALTER FOREIGN TABLE distributors ADD COLUMN address varchar(30); + + + + + To drop a column from a foreign table: + + ALTER FOREIGN TABLE distributors DROP COLUMN address RESTRICT; + + + + + To change the types of two existing columns in one operation: + + ALTER FOREIGN TABLE distributors + ALTER COLUMN address TYPE varchar(80), + ALTER COLUMN name TYPE varchar(100); + + + + + To rename an existing column: + + ALTER FOREIGN TABLE distributors RENAME COLUMN address TO city; + + + + + To rename an existing table: + + ALTER FOREIGN TABLE distributors RENAME TO suppliers; + + + + + To add a not-null constraint to a column: + + ALTER FOREIGN TABLE distributors ALTER COLUMN street SET NOT NULL; + + To remove a not-null constraint from a column: + + ALTER FOREIGN TABLE distributors ALTER COLUMN street DROP NOT NULL; + + + + + To chage options of a column of a foreign table: + + ALTER FOREIGN TABLE myschema.distributors ALTER COLUMN street OPTIONS (ADD opt1 'value', SET opt2, 'value2', DROP opt3 'value3'); + + + + + To add a check constraint to a foreign table: + + ALTER FOREIGN TABLE distributors ADD CONSTRAINT zipchk CHECK (char_length(zipcode) = 5); + + + + + To remove a check constraint from a foreign table and all its children: + + ALTER FOREIGN TABLE distributors DROP CONSTRAINT zipchk; + + + + + To remove a check constraint from a foreign table only: + + ALTER FOREIGN TABLE ONLY distributors DROP CONSTRAINT zipchk; + + + + + To move a foreign table to a different schema: + + ALTER FOREIGN TABLE myschema.distributors SET SCHEMA yourschema; + + + + + To chage options of a foreign table: + + ALTER FOREIGN TABLE myschema.distributors OPTIONS (ADD opt1 'value', SET opt2, 'value2', DROP opt3 'value3'); + + + + + + + Compatibility + + + The forms ADD, DROP, + and SET DATA TYPE + conform with the SQL standard. The other forms are + PostgreSQL extensions of the SQL standard. + Also, the ability to specify more than one manipulation in a single + ALTER FOREIGN TABLE command is an extension. + + + + ALTER FOREIGN TABLE DROP COLUMN can be used to drop the only + column of a foreign table, leaving a zero-column table. This is an + extension of SQL, which disallows zero-column foreign tables. + + + diff --git a/doc/src/sgml/ref/alter_table.sgml b/doc/src/sgml/ref/alter_table.sgml index 784feae..7a1da1d 100644 *** a/doc/src/sgml/ref/alter_table.sgml --- b/doc/src/sgml/ref/alter_table.sgml *************** ALTER TABLE object_name | DATABASE object_name | DOMAIN object_name | + FOREIGN TABLE object_name | FUNCTION function_name ( [ [ argmode ] [ argname ] argtype [, ...] ] ) | INDEX object_name | LARGE OBJECT large_object_oid | *************** COMMENT ON COLUMN my_table.my_column IS *** 247,252 **** --- 248,254 ---- COMMENT ON CONVERSION my_conv IS 'Conversion to UTF8'; COMMENT ON DATABASE my_database IS 'Development Database'; COMMENT ON DOMAIN my_domain IS 'Email Address Domain'; + COMMENT ON FOREIGN TABLE my_schema.my_foreign_table IS 'Employee Information in other database'; COMMENT ON FUNCTION my_function (timestamp) IS 'Returns Roman Numeral'; COMMENT ON INDEX my_index IS 'Enforces uniqueness on employee ID'; COMMENT ON LANGUAGE plpython IS 'Python support for stored procedures'; diff --git a/doc/src/sgml/ref/create_foreign_data_wrapper.sgml b/doc/src/sgml/ref/create_foreign_data_wrapper.sgml index f626d56..e61a725 100644 *** a/doc/src/sgml/ref/create_foreign_data_wrapper.sgml --- b/doc/src/sgml/ref/create_foreign_data_wrapper.sgml *************** PostgreSQL documentation *** 23,28 **** --- 23,29 ---- CREATE FOREIGN DATA WRAPPER name [ VALIDATOR valfunction | NO VALIDATOR ] + [ HANDLER handler | NO HANDLER ] [ OPTIONS ( option 'value' [, ... ] ) ] *************** CREATE FOREIGN DATA WRAPPER + HANDLER handler + + + handler is the + name of a previously registered function that will be called to + retrieve a set of functions for foreign tables. + The validator function must take no arguments. + The return type must be fdw_handler. + + + + + OPTIONS ( option 'value' [, ... ] ) *************** CREATE FOREIGN DATA WRAPPER mywrapper *** 151,158 **** CREATE FOREIGN DATA WRAPPER conforms to ISO/IEC ! 9075-9 (SQL/MED), with the exception that ! the VALIDATOR clause is an extension and the clauses LIBRARY and LANGUAGE are not yet implemented in PostgreSQL. --- 165,172 ---- CREATE FOREIGN DATA WRAPPER conforms to ISO/IEC ! 9075-9 (SQL/MED), with the exception that the VALIDATOR ! and HANDLER clauses are extensions and the clauses LIBRARY and LANGUAGE are not yet implemented in PostgreSQL. diff --git a/doc/src/sgml/ref/create_foreign_table.sgml b/doc/src/sgml/ref/create_foreign_table.sgml index ...572f70f . *** a/doc/src/sgml/ref/create_foreign_table.sgml --- b/doc/src/sgml/ref/create_foreign_table.sgml *************** *** 0 **** --- 1,435 ---- + + + + + CREATE FOREIGN TABLE + 7 + SQL - Language Statements + + + + CREATE FOREIGN TABLE + define a new foreign table + + + + CREATE FOREIGN TABLE + + + + + CREATE FOREIGN TABLE table_name ( [ + { column_name data_type [ OPTIONS ( option 'value' [, ... ] ) ] [ column_constraint [ ... ] ] + | table_constraint + | LIKE parent_table [ like_option ... ] } + [, ... ] + ] ) + [ INHERITS ( parent_table [, ... ] ) ] + SERVER server_name + [ OPTIONS ( option 'value' [, ... ] ) ] + + where column_constraint is: + + [ CONSTRAINT constraint_name ] + { NOT NULL | + NULL | + CHECK ( expression ) + } + + and table_constraint is: + + [ CONSTRAINT constraint_name ] + CHECK ( expression ) + + and like_option is: + + { INCLUDING | EXCLUDING } { DEFAULTS | CONSTRAINTS | COMMENTS | ALL } + + + + + + Description + + + CREATE FOREIGN TABLE will create a new foreign table + in the current database. The table will be owned by the user issuing the + command. + + + + If a schema name is given (for example, CREATE FOREIGN TABLE + myschema.mytable ...) then the table is created in the specified + schema. Otherwise it is created in the current schema. + The name of the foreign table must be + distinct from the name of any other foreign table, table, sequence, index, + or view in the same schema. + + + + CREATE FOREIGN TABLE also automatically creates a data + type that represents the composite type corresponding to one row of + the foreign table. Therefore, foreign tables cannot have the same + name as any existing data type in the same schema. + + + + The optional constraint clauses specify constraints (tests) that + retrieved rows must satisfy for an select operation + to succeed. A constraint is an SQL object that helps define the + set of valid values in the table in various ways. + + + + There are two ways to define constraints: table constraints and + column constraints. A column constraint is defined as part of a + column definition. A table constraint definition is not tied to a + particular column, and it can encompass more than one column. + Every column constraint can also be written as a table constraint; + a column constraint is only a notational convenience for use when the + constraint only affects one column. + + + + To create a foreign table, the foreign-data wrapper of the foreign + server must have handler function. + + + + + Parameters + + + + + table_name + + + The name (optionally schema-qualified) of the table to be created. + + + + + + column_name + + + The name of a column to be created in the new table. + + + + + + data_type + + + The data type of the column. This can include array + specifiers. For more information on the data types supported by + PostgreSQL, refer to . + + + + + + OPTIONS ( option = 'value' [, ...] ) + + + This clause specified options for the new foreign table, or the + column of the new foreign table. + The allowed option names and values are specific to each foreign + data wrapper and are validated using the foreign-data wrapper + library. Option names must be unique. + + + + + + INHERITS ( parent_table [, ... ] ) + + + The optional INHERITS clause specifies a list of + tables from which the new table automatically inherits all + columns. + + + + Use of INHERITS creates a persistent relationship + between the new child table and its parent table(s). Schema + modifications to the parent(s) normally propagate to children + as well, and by default the data of the child table is included in + scans of the parent(s). + + + + If the same column name exists in more than one parent + table, an error is reported unless the data types of the columns + match in each of the parent tables. If there is no conflict, + then the duplicate columns are merged to form a single column in + the new table. If the column name list of the new table + contains a column name that is also inherited, the data type must + likewise match the inherited column(s), and the column + definitions are merged into one. If the + new table explicitly specifies a default value for the column, + this default overrides any defaults from inherited declarations + of the column. Otherwise, any parents that specify default + values for the column must all specify the same default, or an + error will be reported. + + + + CHECK constraints are merged in essentially the same way as + columns: if multiple parent tables and/or the new table definition + contain identically-named CHECK constraints, these + constraints must all have the same check expression, or an error will be + reported. Constraints having the same name and expression will + be merged into one copy. Notice that an unnamed CHECK + constraint in the new table will never be merged, since a unique name + will always be chosen for it. + + + + The parent must not have OIDs because foreign table can't have OIDs. + + + + + + + LIKE parent_table [ like_option ... ] + + + The LIKE clause specifies a table from which + the new table automatically copies all column names, their data types, + and their not-null constraints. + + + Unlike INHERITS, the new table and original table + are completely decoupled after creation is complete. Changes to the + original table will not be applied to the new table, and it is not + possible to include data of the new table in scans of the original + table. + + + Default expressions for the copied column definitions will only be + copied if INCLUDING DEFAULTS is specified. The + default behavior is to exclude default expressions, resulting in the + copied columns in the new table having null defaults. + + + Not-null constraints are always copied to the new table. + CHECK constraints will only be copied if + INCLUDING CONSTRAINTS is specified; other types of + constraints will never be copied. Also, no distinction is made between + column constraints and table constraints — when constraints are + requested, all check constraints are copied. + + + Comments for the copied columns and constraints + will only be copied if INCLUDING COMMENTS + is specified. The default behavior is to exclude comments, resulting in + the copied columns and constraints in the new table having no comments. + + + INCLUDING ALL is an abbreviated form of + INCLUDING DEFAULTS INCLUDING CONSTRAINTS INCLUDING COMMENTS. + + + Note also that unlike INHERITS, columns and + constraints copied by LIKE are not merged with similarly + named columns and constraints. + If the same name is specified explicitly or in another + LIKE clause, an error is signalled. + + + + + + CONSTRAINT constraint_name + + + An optional name for a column or table constraint. If the + constraint is violated, the constraint name is present in error messages, + so constraint names like col must be positive can be used + to communicate helpful constraint information to client applications. + (Double-quotes are needed to specify constraint names that contain spaces.) + If a constraint name is not specified, the system generates a name. + + + + + + NOT NULL + + + The column is not allowed to contain null values. + + + + + + NULL + + + The column is allowed to contain null values. This is the default. + + + + This clause is only provided for compatibility with + non-standard SQL databases. Its use is discouraged in new + applications. + + + + + + CHECK ( expression ) + + + The CHECK clause specifies an expression producing a + Boolean result which new or updated rows must satisfy for an + insert or update operation to succeed. Expressions evaluating + to TRUE or UNKNOWN succeed. Should any row of an insert or + update operation produce a FALSE result an error exception is + raised and the insert or update does not alter the database. A + check constraint specified as a column constraint should + reference that column's value only, while an expression + appearing in a table constraint can reference multiple columns. + + + + Currently, CHECK expressions cannot contain + subqueries nor refer to variables other than columns of the + current row. + + + + + + + + + + + Examples + + + Create foreign table films with film_server: + + + CREATE FOREIGN TABLE films ( + code char(5) NOT NULL, + title varchar(40) NOT NULL, + did integer NOT NULL, + date_prod date, + kind varchar(10), + len interval hour to minute + ) + SERVER film_server; + + + + + Define a check column constraint: + + + CREATE FOREIGN TABLE distributors ( + did integer CHECK (did > 100), + name varchar(40) + ) + SERVER distributor_server; + + + + + Define a check table constraint: + + + CREATE FOREIGN TABLE distributors ( + did integer, + name varchar(40) + CONSTRAINT con1 CHECK (did > 100 AND name <> '') + ) + SERVER distributor_server; + + + + + + + Compatibility + + + The CREATE FOREIGN TABLE command conforms to the + SQL standard, with exceptions listed below. + + + + Column Check Constraints + + + The SQL standard says that CHECK column constraints + can only refer to the column they apply to; only CHECK + table constraints can refer to multiple columns. + PostgreSQL does not enforce this + restriction; it treats column and table check constraints alike. + + + + + <literal>NULL</literal> <quote>Constraint</quote> + + + The NULL constraint (actually a + non-constraint) is a PostgreSQL + extension to the SQL standard that is included for compatibility with some + other database systems (and for symmetry with the NOT + NULL constraint). Since it is the default for any + column, its presence is simply noise. + + + + + Inheritance + + + Multiple inheritance via the INHERITS clause is + a PostgreSQL language extension. + SQL:1999 and later define single inheritance using a + different syntax and different semantics. SQL:1999-style + inheritance is not yet supported by + PostgreSQL. + + + + + Zero-column tables + + + PostgreSQL allows a table of no columns + to be created (for example, CREATE FOREIGN TABLE foo();). This + is an extension from the SQL standard, which does not allow zero-column + tables. Zero-column tables are not in themselves very useful, but + disallowing them creates odd special cases for ALTER TABLE + DROP COLUMN, so it seems cleaner to ignore this spec restriction. + + + + + + + + See Also + + + + + + + + + + diff --git a/doc/src/sgml/ref/create_sequence.sgml b/doc/src/sgml/ref/create_sequence.sgml index 7f94d24..f36b616 100644 *** a/doc/src/sgml/ref/create_sequence.sgml --- b/doc/src/sgml/ref/create_sequence.sgml *************** CREATE [ TEMPORARY | TEMP ] SEQUENCE --- 45,51 ---- Temporary sequences exist in a special schema, so a schema name cannot be given when creating a temporary sequence. The sequence name must be distinct from the name of any other sequence, ! table, index, view, or foreign table in the same schema. diff --git a/doc/src/sgml/ref/create_table.sgml b/doc/src/sgml/ref/create_table.sgml index 8635e80..4314fb1 100644 *** a/doc/src/sgml/ref/create_table.sgml --- b/doc/src/sgml/ref/create_table.sgml *************** CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY *** 96,103 **** schema. Otherwise it is created in the current schema. Temporary tables exist in a special schema, so a schema name cannot be given when creating a temporary table. The name of the table must be ! distinct from the name of any other table, sequence, index, or view ! in the same schema. --- 96,103 ---- schema. Otherwise it is created in the current schema. Temporary tables exist in a special schema, so a schema name cannot be given when creating a temporary table. The name of the table must be ! distinct from the name of any other table, sequence, index, view, ! or foreign table in the same schema. diff --git a/doc/src/sgml/ref/create_view.sgml b/doc/src/sgml/ref/create_view.sgml index 6676383..dd15507 100644 *** a/doc/src/sgml/ref/create_view.sgml --- b/doc/src/sgml/ref/create_view.sgml *************** CREATE [ OR REPLACE ] [ TEMP | TEMPORARY *** 50,56 **** schema. Otherwise it is created in the current schema. Temporary views exist in a special schema, so a schema name cannot be given when creating a temporary view. The name of the view must be ! distinct from the name of any other view, table, sequence, or index in the same schema. --- 50,56 ---- schema. Otherwise it is created in the current schema. Temporary views exist in a special schema, so a schema name cannot be given when creating a temporary view. The name of the view must be ! distinct from the name of any other view, table, sequence, index or foreign table in the same schema. diff --git a/doc/src/sgml/ref/drop_foreign_table.sgml b/doc/src/sgml/ref/drop_foreign_table.sgml index ...1b3af5b . *** a/doc/src/sgml/ref/drop_foreign_table.sgml --- b/doc/src/sgml/ref/drop_foreign_table.sgml *************** *** 0 **** --- 1,123 ---- + + + + + DROP FOREIGN TABLE + 7 + SQL - Language Statements + + + + DROP FOREIGN TABLE + remove a foreign table + + + + DROP FOREIGN TABLE + + + + + DROP FOREIGN TABLE [ IF EXISTS ] name [, ...] [ CASCADE | RESTRICT ] + + + + + Description + + + DROP FOREIGN TABLE removes foreign tables from the database. + Only its owner can drop a foreign table. + + + + DROP FOREIGN TABLE always removes any rules + and constraints that exist for the target table. + However, to drop a foreign table that is referenced by a view, + CASCADE must be + specified. (CASCADE will remove a dependent view entirely, + + + + + Parameters + + + + IF EXISTS + + + Do not throw an error if theforeign table does not exist. A notice is issued + in this case. + + + + + + name + + + The name (optionally schema-qualified) of theforeign table to drop. + + + + + + CASCADE + + + Automatically drop objects that depend on theforeign table (such as + views). + + + + + + RESTRICT + + + Refuse to drop theforeign table if any objects depend on it. This is + the default. + + + + + + + + Examples + + + To destroy two foreign tables, films and + distributors: + + + DROP FOREIGN TABLE films, distributors; + + + + + + Compatibility + + + This command conforms to the ISO/IEC 9075-9 (SQL/MED), except that the + standard only allows one foreign table to be dropped per command, and apart + from the IF EXISTS option, which is a PostgreSQL + extension. + + + + + See Also + + + + + + + + diff --git a/doc/src/sgml/ref/lock.sgml b/doc/src/sgml/ref/lock.sgml index 0c960aa..7b25763 100644 *** a/doc/src/sgml/ref/lock.sgml --- b/doc/src/sgml/ref/lock.sgml *************** LOCK [ TABLE ] [ ONLY ] name ! The name (optionally schema-qualified) of an existing table to lock. If ONLY is specified, only that table is locked. If ONLY is not specified, the table and all its descendant tables (if any) are locked. --- 108,115 ---- name ! The name (optionally schema-qualified) of an existing table ! or a existing foreign table to lock. If ONLY is specified, only that table is locked. If ONLY is not specified, the table and all its descendant tables (if any) are locked. diff --git a/doc/src/sgml/ref/pg_dump.sgml b/doc/src/sgml/ref/pg_dump.sgml index 8242b53..8a18231 100644 *** a/doc/src/sgml/ref/pg_dump.sgml --- b/doc/src/sgml/ref/pg_dump.sgml *************** PostgreSQL documentation *** 408,416 **** ! Dump only tables (or views or sequences) matching table. Multiple tables can be ! selected by writing multiple