pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedALTER FOREIGN DATA WRAPPER can drop dependency on handler
4+ messages / 2 participants
[nested] [flat]
* ALTER FOREIGN DATA WRAPPER can drop dependency on handler
@ 2026-03-18 19:09 Jeff Davis <pgsql@j-davis.com>
0 siblings, 1 reply; 4+ messages in thread
From: Jeff Davis @ 2026-03-18 19:09 UTC (permalink / raw)
To: pgsql-bugs
CREATE FUNCTION test_fdw_handler()
RETURNS fdw_handler
AS :'regresslib', 'test_fdw_handler'
LANGUAGE C;
CREATE FOREIGN DATA WRAPPER test_fdw HANDLER test_fdw_handler;
-- correctly raises dependency ERROR
DROP FUNCTION test_fdw_handler;
ALTER FOREIGN DATA WRAPPER test_fdw VALIDATOR postgresql_fdw_validator;
-- fails to raise dependency error ERROR
DROP FUNCTION test_fdw_handler;
Patch attached.
Note: I found this while investigating a related issue for the FDW
connection function, with patch here:
https://www.postgresql.org/message-id/fd49b44dc65da8e71ab20c1cf1ec7e65921c20f5.camel@j-davis.com
I am keeping this patch separate for a clean backport.
Regards,
Jeff Davis
Attachments:
[text/x-patch] v1-0001-Fix-dependency-on-FDW-handler.patch (935B, ../../35c44a4b7fb76d35418c4d66b775a88f4ce60c86.camel@j-davis.com/2-v1-0001-Fix-dependency-on-FDW-handler.patch)
download | inline diff:
From bf7685cbda2c885fcc6b9aecf11da5c8898db496 Mon Sep 17 00:00:00 2001
From: Jeff Davis <jeff@j-davis.com>
Date: Wed, 18 Mar 2026 11:52:15 -0700
Subject: [PATCH v1] Fix dependency on FDW handler.
ALTER FOREIGN DATA WRAPPER could drop the dependency on the handler
function if it wasn't explicitly specified.
---
src/backend/commands/foreigncmds.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/src/backend/commands/foreigncmds.c b/src/backend/commands/foreigncmds.c
index 45681235782..0b31afd8a79 100644
--- a/src/backend/commands/foreigncmds.c
+++ b/src/backend/commands/foreigncmds.c
@@ -786,6 +786,11 @@ AlterForeignDataWrapper(ParseState *pstate, AlterFdwStmt *stmt)
ereport(WARNING,
(errmsg("changing the foreign-data wrapper handler can change behavior of existing foreign tables")));
}
+ else
+ {
+ /* handler unchanged */
+ fdwhandler = fdwForm->fdwhandler;
+ }
if (validator_given)
{
--
2.43.0
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: ALTER FOREIGN DATA WRAPPER can drop dependency on handler
@ 2026-03-18 19:29 Nathan Bossart <nathandbossart@gmail.com>
parent: Jeff Davis <pgsql@j-davis.com>
0 siblings, 1 reply; 4+ messages in thread
From: Nathan Bossart @ 2026-03-18 19:29 UTC (permalink / raw)
To: Jeff Davis <pgsql@j-davis.com>; +Cc: pgsql-bugs
On Wed, Mar 18, 2026 at 12:09:54PM -0700, Jeff Davis wrote:
> --- a/src/backend/commands/foreigncmds.c
> +++ b/src/backend/commands/foreigncmds.c
> @@ -786,6 +786,11 @@ AlterForeignDataWrapper(ParseState *pstate, AlterFdwStmt *stmt)
> ereport(WARNING,
> (errmsg("changing the foreign-data wrapper handler can change behavior of existing foreign tables")));
> }
> + else
> + {
> + /* handler unchanged */
> + fdwhandler = fdwForm->fdwhandler;
> + }
This matches what we do for the validator a few lines down, so it makes
sense to me. Could it be worth adding a test or two?
--
nathan
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: ALTER FOREIGN DATA WRAPPER can drop dependency on handler
@ 2026-03-18 20:40 Jeff Davis <pgsql@j-davis.com>
parent: Nathan Bossart <nathandbossart@gmail.com>
0 siblings, 1 reply; 4+ messages in thread
From: Jeff Davis @ 2026-03-18 20:40 UTC (permalink / raw)
To: Nathan Bossart <nathandbossart@gmail.com>; +Cc: pgsql-bugs
On Wed, 2026-03-18 at 14:29 -0500, Nathan Bossart wrote:
> This matches what we do for the validator a few lines down, so it
> makes
> sense to me. Could it be worth adding a test or two?
Added a test.
Testing in the other direction (adding HANDLER and leaving VALIDATOR
unspecified, then dropping the validator) is slightly more complex
because I don't want to drop the built-in postgresql_fdw_validator. But
the patch in the other thread can be extended with a new test or two
also, which will cover that case.
Will backport all the way.
Regards,
Jeff Davis
Attachments:
[text/x-patch] v2-0001-Fix-dependency-on-FDW-handler.patch (3.1K, ../../05e57a2122d22962cdd8f344bcb3af7a1e1c487f.camel@j-davis.com/2-v2-0001-Fix-dependency-on-FDW-handler.patch)
download | inline diff:
From 7862e173741dee7172b380c23a24a07cfade41ef Mon Sep 17 00:00:00 2001
From: Jeff Davis <jeff@j-davis.com>
Date: Wed, 18 Mar 2026 11:52:15 -0700
Subject: [PATCH v2] Fix dependency on FDW handler.
ALTER FOREIGN DATA WRAPPER could drop the dependency on the handler
function if it wasn't explicitly specified.
Reviewed-by: Nathan Bossart <nathandbossart@gmail.com>
Discussion: https://postgr.es/m/35c44a4b7fb76d35418c4d66b775a88f4ce60c86.camel@j-davis.com
Backpatch-through: 14
---
src/backend/commands/foreigncmds.c | 5 +++++
src/test/regress/expected/foreign_data.out | 7 +++++++
src/test/regress/sql/foreign_data.sql | 5 +++++
3 files changed, 17 insertions(+)
diff --git a/src/backend/commands/foreigncmds.c b/src/backend/commands/foreigncmds.c
index 45681235782..0b31afd8a79 100644
--- a/src/backend/commands/foreigncmds.c
+++ b/src/backend/commands/foreigncmds.c
@@ -786,6 +786,11 @@ AlterForeignDataWrapper(ParseState *pstate, AlterFdwStmt *stmt)
ereport(WARNING,
(errmsg("changing the foreign-data wrapper handler can change behavior of existing foreign tables")));
}
+ else
+ {
+ /* handler unchanged */
+ fdwhandler = fdwForm->fdwhandler;
+ }
if (validator_given)
{
diff --git a/src/test/regress/expected/foreign_data.out b/src/test/regress/expected/foreign_data.out
index 6af54d9803f..35d75180dff 100644
--- a/src/test/regress/expected/foreign_data.out
+++ b/src/test/regress/expected/foreign_data.out
@@ -106,6 +106,13 @@ ERROR: conflicting or redundant options
LINE 1: ...GN DATA WRAPPER test_fdw HANDLER test_fdw_handler HANDLER in...
^
CREATE FOREIGN DATA WRAPPER test_fdw HANDLER test_fdw_handler;
+-- should preserve dependency on test_fdw_handler
+ALTER FOREIGN DATA WRAPPER test_fdw VALIDATOR postgresql_fdw_validator;
+WARNING: changing the foreign-data wrapper validator can cause the options for dependent objects to become invalid
+DROP FUNCTION test_fdw_handler(); -- ERROR
+ERROR: cannot drop function test_fdw_handler() because other objects depend on it
+DETAIL: foreign-data wrapper test_fdw depends on function test_fdw_handler()
+HINT: Use DROP ... CASCADE to drop the dependent objects too.
DROP FOREIGN DATA WRAPPER test_fdw;
-- ALTER FOREIGN DATA WRAPPER
ALTER FOREIGN DATA WRAPPER foo OPTIONS (nonexistent 'fdw'); -- ERROR
diff --git a/src/test/regress/sql/foreign_data.sql b/src/test/regress/sql/foreign_data.sql
index 084d5559e09..0080bfb8856 100644
--- a/src/test/regress/sql/foreign_data.sql
+++ b/src/test/regress/sql/foreign_data.sql
@@ -67,6 +67,11 @@ CREATE FUNCTION invalid_fdw_handler() RETURNS int LANGUAGE SQL AS 'SELECT 1;';
CREATE FOREIGN DATA WRAPPER test_fdw HANDLER invalid_fdw_handler; -- ERROR
CREATE FOREIGN DATA WRAPPER test_fdw HANDLER test_fdw_handler HANDLER invalid_fdw_handler; -- ERROR
CREATE FOREIGN DATA WRAPPER test_fdw HANDLER test_fdw_handler;
+
+-- should preserve dependency on test_fdw_handler
+ALTER FOREIGN DATA WRAPPER test_fdw VALIDATOR postgresql_fdw_validator;
+DROP FUNCTION test_fdw_handler(); -- ERROR
+
DROP FOREIGN DATA WRAPPER test_fdw;
-- ALTER FOREIGN DATA WRAPPER
--
2.43.0
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: ALTER FOREIGN DATA WRAPPER can drop dependency on handler
@ 2026-03-18 21:41 Nathan Bossart <nathandbossart@gmail.com>
parent: Jeff Davis <pgsql@j-davis.com>
0 siblings, 0 replies; 4+ messages in thread
From: Nathan Bossart @ 2026-03-18 21:41 UTC (permalink / raw)
To: Jeff Davis <pgsql@j-davis.com>; +Cc: pgsql-bugs
On Wed, Mar 18, 2026 at 01:40:38PM -0700, Jeff Davis wrote:
> Added a test.
LGTM
--
nathan
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2026-03-18 21:41 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-03-18 19:09 ALTER FOREIGN DATA WRAPPER can drop dependency on handler Jeff Davis <pgsql@j-davis.com>
2026-03-18 19:29 ` Nathan Bossart <nathandbossart@gmail.com>
2026-03-18 20:40 ` Jeff Davis <pgsql@j-davis.com>
2026-03-18 21:41 ` Nathan Bossart <nathandbossart@gmail.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox