Skip to content

Commit 8df3c7b

Browse files
committed
Document that dependency tracking doesn't consider function bodies.
If there's anyplace in our SGML docs that explains this behavior, I can't find it right at the moment. Add an explanation in "Dependency Tracking" which seems like the authoritative place for such a discussion. Per gripe from Michelle Schwan. While at it, update this section's example of a dependency-related error message: they last looked like that in 8.3. And remove the explanation of dependency updates from pre-7.3 installations, which is probably no longer worth anybody's brain cells to read. The bogus error message example seems like an actual documentation bug, so back-patch to all supported branches. Discussion: <20160620160047.5792.49827@wrigleys.postgresql.org>
1 parent c7aea92 commit 8df3c7b

File tree

1 file changed

+40
-17
lines changed

1 file changed

+40
-17
lines changed

doc/src/sgml/ddl.sgml

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3151,14 +3151,14 @@ ANALYZE measurement;
31513151
To ensure the integrity of the entire database structure,
31523152
<productname>PostgreSQL</productname> makes sure that you cannot
31533153
drop objects that other objects still depend on. For example,
3154-
attempting to drop the products table we had considered in <xref
3154+
attempting to drop the products table we considered in <xref
31553155
linkend="ddl-constraints-fk">, with the orders table depending on
3156-
it, would result in an error message such as this:
3156+
it, would result in an error message like this:
31573157
<screen>
31583158
DROP TABLE products;
31593159

3160-
NOTICE: constraint orders_product_no_fkey on table orders depends on table products
31613160
ERROR: cannot drop table products because other objects depend on it
3161+
DETAIL: constraint orders_product_no_fkey on table orders depends on table products
31623162
HINT: Use DROP ... CASCADE to drop the dependent objects too.
31633163
</screen>
31643164
The error message contains a useful hint: if you do not want to
@@ -3169,11 +3169,12 @@ DROP TABLE products CASCADE;
31693169
and all the dependent objects will be removed. In this case, it
31703170
doesn't remove the orders table, it only removes the foreign key
31713171
constraint. (If you want to check what <command>DROP ... CASCADE</> will do,
3172-
run <command>DROP</> without <literal>CASCADE</> and read the <literal>NOTICE</> messages.)
3172+
run <command>DROP</> without <literal>CASCADE</> and read the
3173+
<literal>DETAIL</> output.)
31733174
</para>
31743175

31753176
<para>
3176-
All drop commands in <productname>PostgreSQL</productname> support
3177+
All <command>DROP</> commands in <productname>PostgreSQL</> support
31773178
specifying <literal>CASCADE</literal>. Of course, the nature of
31783179
the possible dependencies varies with the type of the object. You
31793180
can also write <literal>RESTRICT</literal> instead of
@@ -3185,21 +3186,43 @@ DROP TABLE products CASCADE;
31853186
<para>
31863187
According to the SQL standard, specifying either
31873188
<literal>RESTRICT</literal> or <literal>CASCADE</literal> is
3188-
required. No database system actually enforces that rule, but
3189-
whether the default behavior is <literal>RESTRICT</literal> or
3190-
<literal>CASCADE</literal> varies across systems.
3189+
required in a <command>DROP</> command. No database system actually
3190+
enforces that rule, but whether the default behavior
3191+
is <literal>RESTRICT</literal> or <literal>CASCADE</literal> varies
3192+
across systems.
31913193
</para>
31923194
</note>
31933195

3194-
<note>
3195-
<para>
3196-
Foreign key constraint dependencies and serial column dependencies
3197-
from <productname>PostgreSQL</productname> versions prior to 7.3
3198-
are <emphasis>not</emphasis> maintained or created during the
3199-
upgrade process. All other dependency types will be properly
3200-
created during an upgrade from a pre-7.3 database.
3201-
</para>
3202-
</note>
3196+
<para>
3197+
For user-defined functions, <productname>PostgreSQL</productname> tracks
3198+
dependencies associated with a function's externally-visible properties,
3199+
such as its argument and result types, but <emphasis>not</> dependencies
3200+
that could only be known by examining the function body. As an example,
3201+
consider this situation:
3202+
3203+
<programlisting>
3204+
CREATE TYPE rainbow AS ENUM ('red', 'orange', 'yellow',
3205+
'green', 'blue', 'purple');
3206+
3207+
CREATE TABLE my_colors (color rainbow, note text);
3208+
3209+
CREATE FUNCTION get_color_note (rainbow) RETURNS text AS
3210+
'SELECT note FROM my_colors WHERE color = $1'
3211+
LANGUAGE SQL;
3212+
</programlisting>
3213+
3214+
(See <xref linkend="xfunc-sql"> for an explanation of SQL-language
3215+
functions.) <productname>PostgreSQL</productname> will be aware that
3216+
the <function>get_color_note</> function depends on the <type>rainbow</>
3217+
type: dropping the type would force dropping the function, because its
3218+
argument type would no longer be defined. But <productname>PostgreSQL</>
3219+
will not consider <function>get_color_note</> to depend on
3220+
the <structname>my_colors</> table, and so will not drop the function if
3221+
the table is dropped. While there are disadvantages to this approach,
3222+
there are also benefits. The function is still valid in some sense if the
3223+
table is missing, though executing it would cause an error; creating a new
3224+
table of the same name would allow the function to work again.
3225+
</para>
32033226
</sect1>
32043227

32053228
</chapter>

0 commit comments

Comments
 (0)