@@ -3151,14 +3151,14 @@ ANALYZE measurement;
3151
3151
To ensure the integrity of the entire database structure,
3152
3152
<productname>PostgreSQL</productname> makes sure that you cannot
3153
3153
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
3155
3155
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:
3157
3157
<screen>
3158
3158
DROP TABLE products;
3159
3159
3160
- NOTICE: constraint orders_product_no_fkey on table orders depends on table products
3161
3160
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
3162
3162
HINT: Use DROP ... CASCADE to drop the dependent objects too.
3163
3163
</screen>
3164
3164
The error message contains a useful hint: if you do not want to
@@ -3169,11 +3169,12 @@ DROP TABLE products CASCADE;
3169
3169
and all the dependent objects will be removed. In this case, it
3170
3170
doesn't remove the orders table, it only removes the foreign key
3171
3171
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.)
3173
3174
</para>
3174
3175
3175
3176
<para>
3176
- All drop commands in <productname>PostgreSQL</productname > support
3177
+ All <command>DROP</> commands in <productname>PostgreSQL</> support
3177
3178
specifying <literal>CASCADE</literal>. Of course, the nature of
3178
3179
the possible dependencies varies with the type of the object. You
3179
3180
can also write <literal>RESTRICT</literal> instead of
@@ -3185,21 +3186,43 @@ DROP TABLE products CASCADE;
3185
3186
<para>
3186
3187
According to the SQL standard, specifying either
3187
3188
<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.
3191
3193
</para>
3192
3194
</note>
3193
3195
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>
3203
3226
</sect1>
3204
3227
3205
3228
</chapter>
0 commit comments