@@ -3571,14 +3571,14 @@ ANALYZE measurement;
3571
3571
To ensure the integrity of the entire database structure,
3572
3572
<productname>PostgreSQL</productname> makes sure that you cannot
3573
3573
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
3575
3575
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:
3577
3577
<screen>
3578
3578
DROP TABLE products;
3579
3579
3580
- NOTICE: constraint orders_product_no_fkey on table orders depends on table products
3581
3580
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
3582
3582
HINT: Use DROP ... CASCADE to drop the dependent objects too.
3583
3583
</screen>
3584
3584
The error message contains a useful hint: if you do not want to
@@ -3589,11 +3589,12 @@ DROP TABLE products CASCADE;
3589
3589
and all the dependent objects will be removed. In this case, it
3590
3590
doesn't remove the orders table, it only removes the foreign key
3591
3591
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.)
3593
3594
</para>
3594
3595
3595
3596
<para>
3596
- All drop commands in <productname>PostgreSQL</productname > support
3597
+ All <command>DROP</> commands in <productname>PostgreSQL</> support
3597
3598
specifying <literal>CASCADE</literal>. Of course, the nature of
3598
3599
the possible dependencies varies with the type of the object. You
3599
3600
can also write <literal>RESTRICT</literal> instead of
@@ -3605,21 +3606,43 @@ DROP TABLE products CASCADE;
3605
3606
<para>
3606
3607
According to the SQL standard, specifying either
3607
3608
<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.
3611
3613
</para>
3612
3614
</note>
3613
3615
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>
3623
3646
</sect1>
3624
3647
3625
3648
</chapter>
0 commit comments