class="parameter">refcolumn</replaceable> list is omitted, the
primary key of the <replaceable class="parameter">reftable</replaceable>
is used. The referenced columns must be the columns of a non-deferrable
- unique or primary key constraint in the referenced table. Note that
- foreign key constraints cannot be defined between temporary tables and
- permanent tables.
+ unique or primary key constraint in the referenced table. The user
+ must have <literal>REFERENCES</> permission on the referenced table
+ (either the whole table, or the specific referenced columns).
+ Note that foreign key constraints cannot be defined between temporary
+ tables and permanent tables.
</para>
<para>
<term>REFERENCES</term>
<listitem>
<para>
- To create a foreign key constraint, it is
- necessary to have this privilege on both the referencing and
- referenced columns. The privilege may be granted for all columns
- of a table, or just specific columns.
+ Allows creation of a foreign key constraint referencing the specified
+ table, or specified column(s) of the table. (See the
+ <xref linkend="sql-createtable"> statement.)
</para>
</listitem>
</varlistentry>
<function>currval</function> and <function>nextval</function> functions.
</para>
<para>
- For types and domains, this privilege allow the use of the type or
+ For types and domains, this privilege allows the use of the type or
domain in the creation of tables, functions, and other schema objects.
(Note that it does not control general <quote>usage</quote> of the type,
such as values of the type appearing in queries. It only prevents
which could prevent the owner from changing the type later.)
</para>
<para>
- For foreign-data wrappers, this privilege enables the grantee
- to create new servers using that foreign-data wrapper.
+ For foreign-data wrappers, this privilege allows creation of
+ new servers using the foreign-data wrapper.
</para>
<para>
- For servers, this privilege enables the grantee to create foreign
- tables using the server, and also to create, alter, or drop their own
- user's user mappings associated with that server.
+ For servers, this privilege allows creation of foreign tables using
+ the server. Grantees may also create, alter, or drop their own
+ user mappings associated with that server.
</para>
</listitem>
</varlistentry>
* Now we can check permissions.
*/
checkFkeyPermissions(pkrel, pkattnum, numpks);
- checkFkeyPermissions(rel, fkattnum, numfks);
/*
* Look up the equality operators to use in the constraint.
return ret;
}
-/* Permissions checks for ADD FOREIGN KEY */
+/*
+ * Permissions checks on the referenced table for ADD FOREIGN KEY
+ *
+ * Note: we have already checked that the user owns the referencing table,
+ * else we'd have failed much earlier; no additional checks are needed for it.
+ */
static void
checkFkeyPermissions(Relation rel, int16 *attnums, int natts)
{