Skip to content

Commit 1b322c1

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 d6f549d commit 1b322c1

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

doc/src/sgml/ddl.sgml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5072,8 +5072,9 @@ DROP TABLE products CASCADE;
50725072
</para>
50735073

50745074
<para>
5075-
For user-defined functions, <productname>PostgreSQL</productname> tracks
5076-
dependencies associated with a function's externally-visible properties,
5075+
For a user-defined function or procedure whose body is defined as a string
5076+
literal, <productname>PostgreSQL</productname> tracks
5077+
dependencies associated with the function's externally-visible properties,
50775078
such as its argument and result types, but <emphasis>not</emphasis> dependencies
50785079
that could only be known by examining the function body. As an example,
50795080
consider this situation:
@@ -5101,6 +5102,23 @@ CREATE FUNCTION get_color_note (rainbow) RETURNS text AS
51015102
table is missing, though executing it would cause an error; creating a new
51025103
table of the same name would allow the function to work again.
51035104
</para>
5105+
5106+
<para>
5107+
On the other hand, for a SQL-language function or procedure whose body
5108+
is written in SQL-standard style, the body is parsed at function
5109+
definition time and all dependencies recognized by the parser are
5110+
stored. Thus, if we write the function above as
5111+
5112+
<programlisting>
5113+
CREATE FUNCTION get_color_note (rainbow) RETURNS text
5114+
BEGIN ATOMIC
5115+
SELECT note FROM my_colors WHERE color = $1;
5116+
END;
5117+
</programlisting>
5118+
5119+
then the function's dependency on the <structname>my_colors</structname>
5120+
table will be known and enforced by <command>DROP</command>.
5121+
</para>
51045122
</sect1>
51055123

51065124
</chapter>

0 commit comments

Comments
 (0)