@@ -7883,6 +7883,69 @@ def construct_pg_view(
78837883 END LOOP;
78847884
78857885 RETURN namelist;
7886+ END;
7887+ """ ,
7888+ ),
7889+ # current_schemas() is an emulation of Postgres current_schemas(),
7890+ # fetch_search_path() and recomputeNamespacePath() internal functions.
7891+ trampoline .VersionedFunction (
7892+ name = ('edgedbsql' , 'current_schemas' ),
7893+ args = (
7894+ ('include_implicit' , 'bool' ,),
7895+ ),
7896+ returns = ('name[]' ,),
7897+ language = "plpgsql" ,
7898+ volatility = "stable" ,
7899+ text = """
7900+ DECLARE
7901+ search_path_str text;
7902+ schema_list text[];
7903+ rv name[] := '{}'::name[];
7904+ is_valid_namespace boolean;
7905+ has_pg_catalog boolean;
7906+ resolved_schema text;
7907+ BEGIN
7908+ -- Get the current search_path from the emulated pg_settings view
7909+ SELECT COALESCE(setting, 'public') INTO search_path_str
7910+ FROM edgedbsql_VER.pg_settings
7911+ WHERE name = 'search_path';
7912+
7913+ -- Split using our custom function with comma separator
7914+ schema_list := edgedbsql_VER.split_identifier_string(search_path_str, ',');
7915+
7916+ -- Handle implicit schemas if requested
7917+ IF include_implicit THEN
7918+ -- Temporary schema is not supported yet
7919+
7920+ -- Check if pg_catalog is already present
7921+ has_pg_catalog := 'pg_catalog' = ANY(schema_list);
7922+
7923+ -- Add pg_catalog if not present and GUC variables allow it
7924+ IF NOT has_pg_catalog THEN
7925+ rv := array_append(rv, 'pg_catalog'::name);
7926+ END IF;
7927+ END IF;
7928+
7929+ -- Process each schema element
7930+ FOR i IN 1..array_length(schema_list, 1) LOOP
7931+ -- Handle $user substitution
7932+ IF schema_list[i] = '$user' THEN
7933+ resolved_schema := current_user;
7934+ ELSE
7935+ resolved_schema := schema_list[i];
7936+ END IF;
7937+
7938+ -- Check existence in namespace catalog
7939+ IF EXISTS (
7940+ SELECT 1
7941+ FROM edgedbsql_VER.pg_namespace
7942+ WHERE nspname = resolved_schema
7943+ ) THEN
7944+ rv := array_append(rv, resolved_schema::name);
7945+ END IF;
7946+ END LOOP;
7947+
7948+ RETURN rv;
78867949END;
78877950 """ ,
78887951 ),
0 commit comments