__CDB_FS_List_Foreign_Schemas_PG: Handle order and ignore pg_% schemas automatically

This commit is contained in:
Raul Marin
2019-10-29 18:35:02 +01:00
parent 144c4e722b
commit f7ab3d28a8
2 changed files with 11 additions and 8 deletions
@@ -28,8 +28,12 @@ BEGIN
EXECUTE format('IMPORT FOREIGN SCHEMA %I LIMIT TO (%I) FROM SERVER %I INTO %I', inf_schema, remote_table, server_internal, local_schema); EXECUTE format('IMPORT FOREIGN SCHEMA %I LIMIT TO (%I) FROM SERVER %I INTO %I', inf_schema, remote_table, server_internal, local_schema);
END IF; END IF;
-- Return the result we're interested in -- Return the result we're interested in. Exclude toast and temp schemas
RETURN QUERY EXECUTE format('SELECT schema_name::name AS remote_schema FROM %I.%I', local_schema, remote_table); RETURN QUERY EXECUTE format('
SELECT schema_name::name AS remote_schema FROM %I.%I
WHERE schema_name NOT LIKE %s
ORDER BY remote_schema
', local_schema, remote_table, '''pg_%''');
END END
$$ $$
LANGUAGE PLPGSQL VOLATILE PARALLEL UNSAFE; LANGUAGE PLPGSQL VOLATILE PARALLEL UNSAFE;
@@ -63,7 +67,9 @@ BEGIN
-- Return the result we're interested in -- Return the result we're interested in
-- Note: in this context, schema names are not to be quoted -- Note: in this context, schema names are not to be quoted
RETURN QUERY EXECUTE format($q$SELECT table_name::name AS remote_table FROM %I.%I WHERE table_schema = '%s'$q$, local_schema, remote_table, remote_schema); RETURN QUERY EXECUTE format($q$
SELECT table_name::name AS remote_table FROM %I.%I WHERE table_schema = '%s' ORDER BY table_name
$q$, local_schema, remote_table, remote_schema);
END END
$func$ $func$
LANGUAGE PLPGSQL VOLATILE PARALLEL UNSAFE; LANGUAGE PLPGSQL VOLATILE PARALLEL UNSAFE;
+2 -5
View File
@@ -83,13 +83,10 @@ SET client_min_messages TO notice;
-- Test the listing functions -- Test the listing functions
-- =================================================================== -- ===================================================================
\echo 'Test listing of remote schemas (sunny day)' \echo 'Test listing of remote schemas (sunny day)'
SELECT * FROM cartodb.CDB_Federated_Server_List_Remote_Schemas(remote_server => 'loopback') SELECT * FROM cartodb.CDB_Federated_Server_List_Remote_Schemas(remote_server => 'loopback');
WHERE remote_schema NOT LIKE 'pg_%' -- Exclude toast and temp schemas
ORDER BY remote_schema;
\echo 'Test listing of remote tables (sunny day)' \echo 'Test listing of remote tables (sunny day)'
SELECT * FROM cartodb.CDB_Federated_Server_List_Remote_Tables(remote_server => 'loopback', remote_schema => 'S 1') SELECT * FROM cartodb.CDB_Federated_Server_List_Remote_Tables(remote_server => 'loopback', remote_schema => 'S 1');
ORDER BY remote_table;
-- =================================================================== -- ===================================================================
-- Cleanup -- Cleanup