public inbox for [email protected]
help / color / mirror / Atom feedFrom: Jeff Davis <[email protected]>
To: Nathan Bossart <[email protected]>
Cc: [email protected]
Subject: Re: ALTER FOREIGN DATA WRAPPER can drop dependency on handler
Date: Wed, 18 Mar 2026 13:40:38 -0700
Message-ID: <[email protected]> (raw)
In-Reply-To: <abr9Nhe8UOdoN10L@nathan>
References: <[email protected]>
<abr9Nhe8UOdoN10L@nathan>
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, 2-v2-0001-Fix-dependency-on-FDW-handler.patch)
download | inline diff:
From 7862e173741dee7172b380c23a24a07cfade41ef Mon Sep 17 00:00:00 2001
From: Jeff Davis <[email protected]>
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 <[email protected]>
Discussion: https://postgr.es/m/[email protected]
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
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected]
Subject: Re: ALTER FOREIGN DATA WRAPPER can drop dependency on handler
In-Reply-To: <[email protected]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox