Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 3429210

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 8b9d323 commit 3429210

File tree

1 file changed

+40
-17
lines changed

1 file changed

+40
-17
lines changed

doc/src/sgml/ddl.sgml

+40-17
Original file line numberDiff line numberDiff line change
@@ -3571,14 +3571,14 @@ ANALYZE measurement;
35713571
To ensure the integrity of the entire database structure,
35723572
<productname>PostgreSQL</productname> makes sure that you cannot
35733573
drop objects that other objects still depend on. For example,
3574-
attempting to drop the products table we had considered in <xref
3574+
attempting to drop the products table we considered in <xref
35753575
linkend="ddl-constraints-fk">, with the orders table depending on
3576-
it, would result in an error message such as this:
3576+
it, would result in an error message like this:
35773577
<screen>
35783578
DROP TABLE products;
35793579

3580-
NOTICE: constraint orders_product_no_fkey on table orders depends on table products
35813580
ERROR: cannot drop table products because other objects depend on it
3581+
DETAIL: constraint orders_product_no_fkey on table orders depends on table products
35823582
HINT: Use DROP ... CASCADE to drop the dependent objects too.
35833583
</screen>
35843584
The error message contains a useful hint: if you do not want to
@@ -3589,11 +3589,12 @@ DROP TABLE products CASCADE;
35893589
and all the dependent objects will be removed. In this case, it
35903590
doesn't remove the orders table, it only removes the foreign key
35913591
constraint. (If you want to check what <command>DROP ... CASCADE</> will do,
3592-
run <command>DROP</> without <literal>CASCADE</> and read the <literal>NOTICE</> messages.)
3592+
run <command>DROP</> without <literal>CASCADE</> and read the
3593+
<literal>DETAIL</> output.)
35933594
</para>
35943595

35953596
<para>
3596-
All drop commands in <productname>PostgreSQL</productname> support
3597+
All <command>DROP</> commands in <productname>PostgreSQL</> support
35973598
specifying <literal>CASCADE</literal>. Of course, the nature of
35983599
the possible dependencies varies with the type of the object. You
35993600
can also write <literal>RESTRICT</literal> instead of
@@ -3605,21 +3606,43 @@ DROP TABLE products CASCADE;
36053606
<para>
36063607
According to the SQL standard, specifying either
36073608
<literal>RESTRICT</literal> or <literal>CASCADE</literal> is
3608-
required. No database system actually enforces that rule, but
3609-
whether the default behavior is <literal>RESTRICT</literal> or
3610-
<literal>CASCADE</literal> varies across systems.
3609+
required in a <command>DROP</> command. No database system actually
3610+
enforces that rule, but whether the default behavior
3611+
is <literal>RESTRICT</literal> or <literal>CASCADE</literal> varies
3612+
across systems.
36113613
</para>
36123614
</note>
36133615

3614-
<note>
3615-
<para>
3616-
Foreign key constraint dependencies and serial column dependencies
3617-
from <productname>PostgreSQL</productname> versions prior to 7.3
3618-
are <emphasis>not</emphasis> maintained or created during the
3619-
upgrade process. All other dependency types will be properly
3620-
created during an upgrade from a pre-7.3 database.
3621-
</para>
3622-
</note>
3616+
<para>
3617+
For user-defined functions, <productname>PostgreSQL</productname> tracks
3618+
dependencies associated with a function's externally-visible properties,
3619+
such as its argument and result types, but <emphasis>not</> dependencies
3620+
that could only be known by examining the function body. As an example,
3621+
consider this situation:
3622+
3623+
<programlisting>
3624+
CREATE TYPE rainbow AS ENUM ('red', 'orange', 'yellow',
3625+
'green', 'blue', 'purple');
3626+
3627+
CREATE TABLE my_colors (color rainbow, note text);
3628+
3629+
CREATE FUNCTION get_color_note (rainbow) RETURNS text AS
3630+
'SELECT note FROM my_colors WHERE color = $1'
3631+
LANGUAGE SQL;
3632+
</programlisting>
3633+
3634+
(See <xref linkend="xfunc-sql"> for an explanation of SQL-language
3635+
functions.) <productname>PostgreSQL</productname> will be aware that
3636+
the <function>get_color_note</> function depends on the <type>rainbow</>
3637+
type: dropping the type would force dropping the function, because its
3638+
argument type would no longer be defined. But <productname>PostgreSQL</>
3639+
will not consider <function>get_color_note</> to depend on
3640+
the <structname>my_colors</> table, and so will not drop the function if
3641+
the table is dropped. While there are disadvantages to this approach,
3642+
there are also benefits. The function is still valid in some sense if the
3643+
table is missing, though executing it would cause an error; creating a new
3644+
table of the same name would allow the function to work again.
3645+
</para>
36233646
</sect1>
36243647

36253648
</chapter>

0 commit comments

Comments
 (0)