Movatterモバイル変換


[0]ホーム

URL:



Facebook
Postgres Pro
Facebook
Downloads

CREATE FOREIGN TABLE

Name

CREATE FOREIGN TABLE -- define a new foreign table

Synopsis

CREATE FOREIGN TABLE [ IF NOT EXISTS ]table_name ( [column_namedata_type [ OPTIONS (option 'value' [, ... ] ) ] [ COLLATEcollation ] [column_constraint [ ... ] ]    [, ... ]] )  SERVERserver_name[ OPTIONS (option 'value' [, ... ] ) ]wherecolumn_constraint is:[ CONSTRAINTconstraint_name ]{ NOT NULL |  NULL |  DEFAULTdefault_expr }

Description

CREATE FOREIGN TABLE creates 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, view, or materialized 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 foreign table, you must haveUSAGE privilege on the foreign server, as well asUSAGE privilege on all column types used in the table.

Parameters

IF NOT EXISTS

Do not throw an error if a relation with the same name already exists. A notice is issued in this case. Note that there is no guarantee that the existing relation is anything like the one that would have been created.

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 byPostgreSQL, refer toChapter 8.

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.

DEFAULTdefault_expr

TheDEFAULT 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

The name of an existing foreign server to use for the foreign table. For details on defining a server, seeCREATE SERVER.

OPTIONS (option 'value' [, ...] )

Options to be associated with the new foreign table or one of its columns. The allowed option names and values are specific to each foreign data wrapper and are validated using the foreign-data wrapper's validator function. Duplicate option names are not allowed (although it's OK for a table option and a column option to have the same name).

Examples

Create foreign tablefilms, which will be accessed through the serverfilm_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

TheCREATE FOREIGN TABLE command largely conforms to theSQL standard; however, much as withCREATE TABLE,NULL constraints and zero-column foreign tables are permitted. The ability to specify a default value is also aPostgreSQL extension.


PrevHomeNext
CREATE FOREIGN DATA WRAPPERUpCREATE FUNCTION
Go to PostgreSQL 9.4
By continuing to browse this website, you agree to the use of cookies. Go toPrivacy Policy.

[8]ページ先頭

©2009-2025 Movatter.jp