<commit_before>--------------------------------------------------------------------------------
-- Private functions
--------------------------------------------------------------------------------

--
-- List the schemas of a remote PG server
-- 
CREATE OR REPLACE FUNCTION @extschema@.__CDB_FS_List_Foreign_Schemas_PG(server_internal name)
RETURNS TABLE(remote_schema name)
AS $$
DECLARE
    -- Import schemata from the information schema
    --
    -- "The view schemata contains all schemas in the current database
    -- that the current user has access to (by way of being the owner
    -- or having some privilege)."
    -- See https://www.postgresql.org/docs/11/infoschema-schemata.html
    --
    -- "The information schema is defined in the SQL standard and can
    -- therefore be expected to be portable and remain stable"
    -- See https://www.postgresql.org/docs/11/information-schema.html
    inf_schema name := 'information_schema';
    remote_table name := 'schemata';
    local_schema name := @extschema@.__CDB_FS_Create_Schema(server_internal, inf_schema);
    role_name name := @extschema@.__CDB_FS_Generate_Server_Role_Name(server_internal);
BEGIN
    -- Import the foreign schemata table
    IF NOT EXISTS (
        SELECT * FROM pg_class
        WHERE relnamespace = (SELECT oid FROM pg_namespace WHERE nspname = local_schema)
        AND relname = remote_table
    ) THEN
        EXECUTE format('IMPORT FOREIGN SCHEMA %I LIMIT TO (%I) FROM SERVER %I INTO %I',
                    inf_schema, remote_table, server_internal, local_schema);
    END IF;

    -- Return the result we're interested in. Exclude toast and temp schemas
    BEGIN<commit_msg>__CDB_FS_List_Foreign_Schemas_PG: Remove extra role generation<commit_after>--------------------------------------------------------------------------------
-- Private functions
--------------------------------------------------------------------------------

--
-- List the schemas of a remote PG server
-- 
CREATE OR REPLACE FUNCTION @extschema@.__CDB_FS_List_Foreign_Schemas_PG(server_internal name)
RETURNS TABLE(remote_schema name)
AS $$
DECLARE
    -- Import schemata from the information schema
    --
    -- "The view schemata contains all schemas in the current database
    -- that the current user has access to (by way of being the owner
    -- or having some privilege)."
    -- See https://www.postgresql.org/docs/11/infoschema-schemata.html
    --
    -- "The information schema is defined in the SQL standard and can
    -- therefore be expected to be portable and remain stable"
    -- See https://www.postgresql.org/docs/11/information-schema.html
    inf_schema name := 'information_schema';
    remote_table name := 'schemata';
    local_schema name := @extschema@.__CDB_FS_Create_Schema(server_internal, inf_schema);
BEGIN
    -- Import the foreign schemata table
    IF NOT EXISTS (
        SELECT * FROM pg_class
        WHERE relnamespace = (SELECT oid FROM pg_namespace WHERE nspname = local_schema)
        AND relname = remote_table
    ) THEN
        EXECUTE format('IMPORT FOREIGN SCHEMA %I LIMIT TO (%I) FROM SERVER %I INTO %I',
                    inf_schema, remote_table, server_internal, local_schema);
    END IF;

    -- Return the result we're interested in. Exclude toast and temp schemas
    BEGIN
{'fraction_non_alphanumeric': 0.16948640483383687, 'fraction_numerical': 0.002416918429003021, 'mean_word_length': 2.1653919694072656, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3865771', 'n_tokens_mistral': 888, 'n_tokens_neox': 853, 'n_words': 296}