Skip to content

Commit 0211544

Browse files
committed
Doc: explain about dependency tracking for new-style SQL functions.
5.14 Dependency Tracking was not updated when we added new-style SQL functions. Improve that. Noted by Sami Imseih. Back-patch to v14 where new-style SQL functions came in. Discussion: https://postgr.es/m/2C1933AB-C2F8-499B-9D18-4AC1882256A0@amazon.com
1 parent 0161074 commit 0211544

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

doc/src/sgml/ddl.sgml

+20-2
Original file line numberDiff line numberDiff line change
@@ -5235,8 +5235,9 @@ DROP TABLE products CASCADE;
52355235
</para>
52365236

52375237
<para>
5238-
For user-defined functions, <productname>PostgreSQL</productname> tracks
5239-
dependencies associated with a function's externally-visible properties,
5238+
For a user-defined function or procedure whose body is defined as a string
5239+
literal, <productname>PostgreSQL</productname> tracks
5240+
dependencies associated with the function's externally-visible properties,
52405241
such as its argument and result types, but <emphasis>not</emphasis> dependencies
52415242
that could only be known by examining the function body. As an example,
52425243
consider this situation:
@@ -5264,6 +5265,23 @@ CREATE FUNCTION get_color_note (rainbow) RETURNS text AS
52645265
table is missing, though executing it would cause an error; creating a new
52655266
table of the same name would allow the function to work again.
52665267
</para>
5268+
5269+
<para>
5270+
On the other hand, for a SQL-language function or procedure whose body
5271+
is written in SQL-standard style, the body is parsed at function
5272+
definition time and all dependencies recognized by the parser are
5273+
stored. Thus, if we write the function above as
5274+
5275+
<programlisting>
5276+
CREATE FUNCTION get_color_note (rainbow) RETURNS text
5277+
BEGIN ATOMIC
5278+
SELECT note FROM my_colors WHERE color = $1;
5279+
END;
5280+
</programlisting>
5281+
5282+
then the function's dependency on the <structname>my_colors</structname>
5283+
table will be known and enforced by <command>DROP</command>.
5284+
</para>
52675285
</sect1>
52685286

52695287
</chapter>

0 commit comments

Comments
 (0)