Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f28d9b1

Browse files
committed
Document SQL functions' behavior of parsing the whole function at once.
Haribabu Kommi, somewhat rewritten by me
1 parent bfaa8c6 commit f28d9b1

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

doc/src/sgml/xfunc.sgml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,21 @@ SELECT clean_emp();
143143
</screen>
144144
</para>
145145

146+
<note>
147+
<para>
148+
The entire body of a SQL function is parsed before any of it is
149+
executed. While a SQL function can contain commands that alter
150+
the system catalogs (e.g., <command>CREATE TABLE</>), the effects
151+
of such commands will not be visible during parse analysis of
152+
later commands in the function. Thus, for example,
153+
<literal>CREATE TABLE foo (...); INSERT INTO foo VALUES(...);</literal>
154+
will not work as desired if packaged up into a single SQL function,
155+
since <structname>foo</> won't exist yet when the <command>INSERT</>
156+
command is parsed. It's recommended to use <application>PL/PgSQL</>
157+
instead of a SQL function in this type of situation.
158+
</para>
159+
</note>
160+
146161
<para>
147162
The syntax of the <command>CREATE FUNCTION</command> command requires
148163
the function body to be written as a string constant. It is usually

0 commit comments

Comments
 (0)