ALTER FOREIGN DATA WRAPPER can drop dependency on handler

Started by Jeff Davis8 months ago4 messagesbugs
Jump to latest
#1Jeff Davis
pgsql@j-davis.com

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:

/messages/by-id/fd49b44dc65da8e71ab20c1cf1ec7e65921c20f5.camel@j-davis.com

I am keeping this patch separate for a clean backport.

Regards,
Jeff Davis

Attachments:

v1-0001-Fix-dependency-on-FDW-handler.patchtext/x-patch; charset=UTF-8; name=v1-0001-Fix-dependency-on-FDW-handler.patchDownload+5-1
#2Nathan Bossart
nathandbossart@gmail.com
In reply to: Jeff Davis (#1)
Re: ALTER FOREIGN DATA WRAPPER can drop dependency on handler

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

#3Jeff Davis
pgsql@j-davis.com
In reply to: Nathan Bossart (#2)
Re: ALTER FOREIGN DATA WRAPPER can drop dependency on handler

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:

v2-0001-Fix-dependency-on-FDW-handler.patchtext/x-patch; charset=UTF-8; name=v2-0001-Fix-dependency-on-FDW-handler.patchDownload+17-1
#4Nathan Bossart
nathandbossart@gmail.com
In reply to: Jeff Davis (#3)
Re: ALTER FOREIGN DATA WRAPPER can drop dependency on handler

On Wed, Mar 18, 2026 at 01:40:38PM -0700, Jeff Davis wrote:

Added a test.

LGTM

--
nathan