table of contents
CREATE FOREIGN TABLE(7) | PostgreSQL 9.2.24 Documentation | CREATE FOREIGN TABLE(7) |
NAME¶
CREATE_FOREIGN_TABLE - define a new foreign table
SYNOPSIS¶
CREATE FOREIGN TABLE [ IF NOT EXISTS ] table_name ( [
{ column_name data_type [ OPTIONS ( option 'value' [, ... ] ) ] [ NULL | NOT NULL ] }
[, ... ] ] )
SERVER server_name [ OPTIONS ( option 'value' [, ... ] ) ]
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.
To be able to create a table, you must have USAGE privilege on all column types.
PARAMETERS¶
IF NOT EXISTS
table_name
column_name
data_type
NOT NULL
NULL
This clause is only provided for compatibility with non-standard SQL databases. Its use is discouraged in new applications.
server_name
OPTIONS ( option 'value' [, ...] )
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;
COMPATIBILITY¶
The CREATE FOREIGN TABLE command largely conforms to the SQL standard; however, much as with CREATE TABLE, NULL constraints and zero-column foreign tables are permitted.
SEE ALSO¶
ALTER FOREIGN TABLE (ALTER_FOREIGN_TABLE(7)), DROP FOREIGN TABLE (DROP_FOREIGN_TABLE(7)), CREATE TABLE (CREATE_TABLE(7)), CREATE SERVER (CREATE_SERVER(7))
2017-11-06 | PostgreSQL 9.2.24 |