Src |
CREATE OR REPLACE FUNCTION sesar_get_odp_count(IN "" text, IN "" text)
RETURNS TABLE(t_column_name text, t_count bigint) AS
$$
DECLARE
p_schema TEXT := $1;
p_tabname TEXT := $2;
v_sql_statement TEXT;
BEGIN
SELECT STRING_AGG( 'SELECT '''
|| column_name
|| ''' as column_name,'
|| ' count('
|| column_name
|| ') FROM '
|| table_schema
|| '.'
|| table_name
|| ' where igsn_prefix = ''ODP'' '
,' UNION ALL ' ) INTO v_sql_statement
FROM information_schema.columns
WHERE table_schema = p_schema
AND table_name = p_tabname;
IF v_sql_statement IS NOT NULL THEN
RETURN QUERY EXECUTE v_sql_statement;
END IF;
END
$$
LANGUAGE plpgsql VOLATILE
COST 100
ROWS 1000;
|