mirror of
https://github.com/postgres/postgres.git
synced 2025-09-02 04:21:28 +03:00
Allow CHECK constraints to be placed on foreign tables.
As with NOT NULL constraints, we consider that such constraints are merely reports of constraints that are being enforced by the remote server (or other underlying storage mechanism). Their only real use is to allow planner optimizations, for example in constraint-exclusion checks. Thus, the code changes here amount to little more than removal of the error that was formerly thrown for applying CHECK to a foreign table. (In passing, do a bit of cleanup of the ALTER FOREIGN TABLE reference page, which had accumulated some weird decisions about ordering etc.) Shigeru Hanada and Etsuro Fujita, reviewed by Kyotaro Horiguchi and Ashutosh Bapat.
This commit is contained in:
@@ -42,6 +42,8 @@ ALTER FOREIGN TABLE [ IF EXISTS ] <replaceable class="PARAMETER">name</replaceab
|
||||
ALTER [ COLUMN ] <replaceable class="PARAMETER">column_name</replaceable> SET ( <replaceable class="PARAMETER">attribute_option</replaceable> = <replaceable class="PARAMETER">value</replaceable> [, ... ] )
|
||||
ALTER [ COLUMN ] <replaceable class="PARAMETER">column_name</replaceable> RESET ( <replaceable class="PARAMETER">attribute_option</replaceable> [, ... ] )
|
||||
ALTER [ COLUMN ] <replaceable class="PARAMETER">column_name</replaceable> OPTIONS ( [ ADD | SET | DROP ] <replaceable class="PARAMETER">option</replaceable> ['<replaceable class="PARAMETER">value</replaceable>'] [, ... ])
|
||||
ADD <replaceable class="PARAMETER">table_constraint</replaceable>
|
||||
DROP CONSTRAINT [ IF EXISTS ] <replaceable class="PARAMETER">constraint_name</replaceable> [ RESTRICT | CASCADE ]
|
||||
DISABLE TRIGGER [ <replaceable class="PARAMETER">trigger_name</replaceable> | ALL | USER ]
|
||||
ENABLE TRIGGER [ <replaceable class="PARAMETER">trigger_name</replaceable> | ALL | USER ]
|
||||
ENABLE REPLICA TRIGGER <replaceable class="PARAMETER">trigger_name</replaceable>
|
||||
@@ -87,16 +89,6 @@ ALTER FOREIGN TABLE [ IF EXISTS ] <replaceable class="PARAMETER">name</replaceab
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><literal>IF EXISTS</literal></term>
|
||||
<listitem>
|
||||
<para>
|
||||
Do not throw an error if the foreign table does not exist. A notice is
|
||||
issued in this case.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><literal>SET DATA TYPE</literal></term>
|
||||
<listitem>
|
||||
@@ -152,6 +144,38 @@ ALTER FOREIGN TABLE [ IF EXISTS ] <replaceable class="PARAMETER">name</replaceab
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><literal>ADD <replaceable class="PARAMETER">table_constraint</replaceable></literal></term>
|
||||
<listitem>
|
||||
<para>
|
||||
This form adds a new constraint to a foreign table, using the same
|
||||
syntax as <xref linkend="SQL-CREATEFOREIGNTABLE">.
|
||||
Currently only <literal>CHECK</> constraints are supported.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Unlike the case when adding a constraint to a regular table, nothing is
|
||||
done to verify the constraint is correct; rather, this action simply
|
||||
declares that some new condition holds for all rows in the foreign
|
||||
table. (See the discussion in <xref linkend="SQL-CREATEFOREIGNTABLE">.)
|
||||
Note that constraints on foreign tables cannot be marked
|
||||
<literal>NOT VALID</> since such constraints are simply declarative.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><literal>DROP CONSTRAINT [ IF EXISTS ]</literal></term>
|
||||
<listitem>
|
||||
<para>
|
||||
This form drops the specified constraint on a foreign table.
|
||||
If <literal>IF EXISTS</literal> is specified and the constraint
|
||||
does not exist, no error is thrown.
|
||||
In this case a notice is issued instead.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><literal>DISABLE</literal>/<literal>ENABLE [ REPLICA | ALWAYS ] TRIGGER</literal></term>
|
||||
<listitem>
|
||||
@@ -173,6 +197,21 @@ ALTER FOREIGN TABLE [ IF EXISTS ] <replaceable class="PARAMETER">name</replaceab
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><literal>OPTIONS ( [ ADD | SET | DROP ] <replaceable class="PARAMETER">option</replaceable> ['<replaceable class="PARAMETER">value</replaceable>'] [, ... ] )</literal></term>
|
||||
<listitem>
|
||||
<para>
|
||||
Change options for the foreign table or one of its columns.
|
||||
<literal>ADD</>, <literal>SET</>, and <literal>DROP</>
|
||||
specify the action to be performed. <literal>ADD</> is assumed
|
||||
if no operation is explicitly specified. Duplicate option names are not
|
||||
allowed (although it's OK for a table option and a column option to have
|
||||
the same name). Option names and values are also validated using the
|
||||
foreign data wrapper library.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><literal>RENAME</literal></term>
|
||||
<listitem>
|
||||
@@ -192,21 +231,6 @@ ALTER FOREIGN TABLE [ IF EXISTS ] <replaceable class="PARAMETER">name</replaceab
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><literal>OPTIONS ( [ ADD | SET | DROP ] <replaceable class="PARAMETER">option</replaceable> ['<replaceable class="PARAMETER">value</replaceable>'] [, ... ] )</literal></term>
|
||||
<listitem>
|
||||
<para>
|
||||
Change options for the foreign table or one of its columns.
|
||||
<literal>ADD</>, <literal>SET</>, and <literal>DROP</>
|
||||
specify the action to be performed. <literal>ADD</> is assumed
|
||||
if no operation is explicitly specified. Duplicate option names are not
|
||||
allowed (although it's OK for a table option and a column option to have
|
||||
the same name). Option names and values are also validated using the
|
||||
foreign data wrapper library.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
</variablelist>
|
||||
</para>
|
||||
|
||||
@@ -218,6 +242,12 @@ ALTER FOREIGN TABLE [ IF EXISTS ] <replaceable class="PARAMETER">name</replaceab
|
||||
columns in a single command.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
If the command is written as <literal>ALTER FOREIGN TABLE IF EXISTS ...</>
|
||||
and the foreign table does not exist, no error is thrown. A notice is
|
||||
issued in this case.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
You must own the table to use <command>ALTER FOREIGN TABLE</>.
|
||||
To change the schema of a foreign table, you must also have
|
||||
@@ -284,12 +314,30 @@ ALTER FOREIGN TABLE [ IF EXISTS ] <replaceable class="PARAMETER">name</replaceab
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><replaceable class="PARAMETER">table_constraint</replaceable></term>
|
||||
<listitem>
|
||||
<para>
|
||||
New table constraint for the foreign table.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><replaceable class="PARAMETER">constraint_name</replaceable></term>
|
||||
<listitem>
|
||||
<para>
|
||||
Name of an existing constraint to drop.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><literal>CASCADE</literal></term>
|
||||
<listitem>
|
||||
<para>
|
||||
Automatically drop objects that depend on the dropped column
|
||||
(for example, views referencing the column).
|
||||
or constraint (for example, views referencing the column).
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
@@ -298,7 +346,7 @@ ALTER FOREIGN TABLE [ IF EXISTS ] <replaceable class="PARAMETER">name</replaceab
|
||||
<term><literal>RESTRICT</literal></term>
|
||||
<listitem>
|
||||
<para>
|
||||
Refuse to drop the column if there are any dependent
|
||||
Refuse to drop the column or constraint if there are any dependent
|
||||
objects. This is the default behavior.
|
||||
</para>
|
||||
</listitem>
|
||||
@@ -365,10 +413,10 @@ ALTER FOREIGN TABLE [ IF EXISTS ] <replaceable class="PARAMETER">name</replaceab
|
||||
<para>
|
||||
Consistency with the foreign server is not checked when a column is added
|
||||
or removed with <literal>ADD COLUMN</literal> or
|
||||
<literal>DROP COLUMN</literal>, a <literal>NOT NULL</> constraint is
|
||||
added, or a column type is changed with <literal>SET DATA TYPE</>. It is
|
||||
the user's responsibility to ensure that the table definition matches the
|
||||
remote side.
|
||||
<literal>DROP COLUMN</literal>, a <literal>NOT NULL</>
|
||||
or <literal>CHECK</> constraint is added, or a column type is changed
|
||||
with <literal>SET DATA TYPE</>. It is the user's responsibility to ensure
|
||||
that the table definition matches the remote side.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
@@ -413,4 +461,13 @@ ALTER FOREIGN TABLE myschema.distributors OPTIONS (ADD opt1 'value', SET opt2, '
|
||||
extension of SQL, which disallows zero-column foreign tables.
|
||||
</para>
|
||||
</refsect1>
|
||||
|
||||
<refsect1>
|
||||
<title>See Also</title>
|
||||
|
||||
<simplelist type="inline">
|
||||
<member><xref linkend="sql-createforeigntable"></member>
|
||||
<member><xref linkend="sql-dropforeigntable"></member>
|
||||
</simplelist>
|
||||
</refsect1>
|
||||
</refentry>
|
||||
|
Reference in New Issue
Block a user