recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
}
+ if (OidIsValid(fdwconnection))
+ {
+ referenced.classId = ProcedureRelationId;
+ referenced.objectId = fdwconnection;
+ referenced.objectSubId = 0;
+ recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
+ }
+
recordDependencyOnOwner(ForeignDataWrapperRelationId, fdwId, ownerId);
/* dependency on extension */
{
repl_val[Anum_pg_foreign_data_wrapper_fdwconnection - 1] = ObjectIdGetDatum(fdwconnection);
repl_repl[Anum_pg_foreign_data_wrapper_fdwconnection - 1] = true;
+
+ /*
+ * If the connection function is changed, behavior of dependent
+ * subscriptions can change. If NO CONNECTION, dependent
+ * subscriptions will fail.
+ */
+ if (OidIsValid(fdwForm->fdwconnection))
+ {
+ if (OidIsValid(fdwconnection))
+ ereport(WARNING,
+ (errmsg("changing the foreign-data wrapper connection function can cause "
+ "the options for dependent objects to become invalid")));
+ else
+ ereport(WARNING,
+ (errmsg("removing the foreign-data wrapper connection function will cause "
+ "dependent subscriptions to fail")));
+ }
+ }
+ else
+ {
+ /* connection function unchanged */
+ fdwconnection = fdwForm->fdwconnection;
}
/*
ObjectAddressSet(myself, ForeignDataWrapperRelationId, fdwId);
/* Update function dependencies if we changed them */
- if (handler_given || validator_given)
+ if (handler_given || validator_given || connection_given)
{
ObjectAddress referenced;
referenced.objectSubId = 0;
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
}
+
+ if (OidIsValid(fdwconnection))
+ {
+ referenced.classId = ProcedureRelationId;
+ referenced.objectId = fdwconnection;
+ referenced.objectSubId = 0;
+ recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
+ }
}
InvokeObjectPostAlterHook(ForeignDataWrapperRelationId, fdwId, 0);
*/
/* yyyymmddN */
-#define CATALOG_VERSION_NO 202603191
+#define CATALOG_VERSION_NO 202603201
#endif
RETURNS fdw_handler
AS :'regresslib', 'test_fdw_handler'
LANGUAGE C;
+CREATE FUNCTION test_fdw_connection(oid, oid, internal)
+ RETURNS text
+ AS :'regresslib', 'test_fdw_connection'
+ LANGUAGE C;
-- Clean up in case a prior regression run failed
-- Suppress NOTICE messages when roles don't exist
SET client_min_messages TO 'warning';
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
+-- should preserve dependencies on test_fdw_handler and test_fdw_connection
+ALTER FOREIGN DATA WRAPPER test_fdw CONNECTION test_fdw_connection;
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 FUNCTION test_fdw_connection(oid, oid, internal); -- ERROR
+ERROR: cannot drop function test_fdw_connection(oid,oid,internal) because other objects depend on it
+DETAIL: foreign-data wrapper test_fdw depends on function test_fdw_connection(oid,oid,internal)
+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
SET SESSION AUTHORIZATION regress_subscription_user;
REVOKE CREATE ON DATABASE REGRESSION FROM regress_subscription_user3;
DROP SERVER test_server;
+-- fail, FDW is dependent
+DROP FUNCTION test_fdw_connection(oid, oid, internal);
+ERROR: cannot drop function test_fdw_connection(oid,oid,internal) because other objects depend on it
+DETAIL: foreign-data wrapper test_fdw depends on function test_fdw_connection(oid,oid,internal)
+HINT: Use DROP ... CASCADE to drop the dependent objects too.
+-- warn
+ALTER FOREIGN DATA WRAPPER test_fdw NO CONNECTION;
+WARNING: removing the foreign-data wrapper connection function will cause dependent subscriptions to fail
+DROP FUNCTION test_fdw_connection(oid, oid, internal);
DROP FOREIGN DATA WRAPPER test_fdw;
-- fail - invalid connection string during ALTER
ALTER SUBSCRIPTION regress_testsub CONNECTION 'foobar';
AS :'regresslib', 'test_fdw_handler'
LANGUAGE C;
+CREATE FUNCTION test_fdw_connection(oid, oid, internal)
+ RETURNS text
+ AS :'regresslib', 'test_fdw_connection'
+ LANGUAGE C;
+
-- Clean up in case a prior regression run failed
-- Suppress NOTICE messages when roles don't exist
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
+-- should preserve dependencies on test_fdw_handler and test_fdw_connection
+ALTER FOREIGN DATA WRAPPER test_fdw CONNECTION test_fdw_connection;
ALTER FOREIGN DATA WRAPPER test_fdw VALIDATOR postgresql_fdw_validator;
DROP FUNCTION test_fdw_handler(); -- ERROR
+DROP FUNCTION test_fdw_connection(oid, oid, internal); -- ERROR
DROP FOREIGN DATA WRAPPER test_fdw;
REVOKE CREATE ON DATABASE REGRESSION FROM regress_subscription_user3;
DROP SERVER test_server;
+
+-- fail, FDW is dependent
+DROP FUNCTION test_fdw_connection(oid, oid, internal);
+-- warn
+ALTER FOREIGN DATA WRAPPER test_fdw NO CONNECTION;
+
+DROP FUNCTION test_fdw_connection(oid, oid, internal);
+
DROP FOREIGN DATA WRAPPER test_fdw;
-- fail - invalid connection string during ALTER