Src |
CREATE OR REPLACE FUNCTION sesar_get_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
|| ''','
|| ' count('
|| column_name
|| ') FROM '
|| table_schema
|| '.'
|| table_name
,' 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;
|