| From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
|---|---|
| To: | pgsql-committers(at)lists(dot)postgresql(dot)org |
| Subject: | pgsql: Issue a NOTICE if a created function depends on any temp objects |
| Date: | 2025-11-23 20:03:05 |
| Message-ID: | E1vNGIa-0012OI-2x@gemulon.postgresql.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-committers |
Issue a NOTICE if a created function depends on any temp objects.
We don't have an official concept of temporary functions. (You can
make one explicitly in pg_temp, but then you have to explicitly
schema-qualify it on every call.) However, until now we were quite
laissez-faire about whether a non-temporary function could depend on
a temporary object, such as a temp table or view. If one does,
it will silently go away at end of session, due to the automatic
DROP ... CASCADE on the session's temporary objects. People have
complained that that's surprising; however, we can't really forbid
it because other people (including our own regression tests) rely
on being able to do it. Let's compromise by emitting a NOTICE
at CREATE FUNCTION time. This is somewhat comparable to our
ancient practice of emitting a NOTICE when forcing a view to
become temp because it depends on temp tables.
Along the way, refactor recordDependencyOnExpr() so that the
dependencies of an expression can be combined with other
dependencies, instead of being emitted separately and perhaps
duplicatively.
We should probably make the implementation of temp-by-default
views use the same infrastructure used here, but that's for
another patch. It's unclear whether there are any other object
classes that deserve similar treatment.
Author: Jim Jones <jim(dot)jones(at)uni-muenster(dot)de>
Reviewed-by: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Discussion: https://postgr.es/m/19cf6ae1-04cd-422c-a760-d7e75fe6cba9@uni-muenster.de
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/572c40ba94ef6350c8dd51539ac7d932c1d1a12a
Modified Files
--------------
src/backend/catalog/dependency.c | 99 +++++++++++++++++++---
src/backend/catalog/pg_proc.c | 41 +++++++--
src/backend/commands/functioncmds.c | 2 +
src/backend/commands/typecmds.c | 3 +
src/include/catalog/dependency.h | 7 ++
.../isolation/expected/temp-schema-cleanup.out | 4 +
src/test/regress/expected/create_function_sql.out | 10 +++
src/test/regress/expected/rangefuncs.out | 4 +
src/test/regress/expected/returning.out | 4 +
src/test/regress/expected/rowtypes.out | 10 +++
src/test/regress/sql/create_function_sql.sql | 11 +++
11 files changed, 176 insertions(+), 19 deletions(-)
| From | Date | Subject | |
|---|---|---|---|
| Previous Message | Fujii Masao | 2025-11-23 14:05:07 | pgsql: psql: Improve tab-completion for PREPARE. |