Created
July 31, 2020 18:07
-
-
Save RaulMedeiros/66e7b02688f9900fdb11c1d6ad6e6dd9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE FUNCTION query_builder(tab_name text) RETURNS table ( aaa int ) LANGUAGE plpgsql AS $$ | |
DECLARE | |
built_query varchar; | |
BEGIN | |
SELECT 'SELECT ( | |
cast(f."' || STRING_AGG (column_name, '" IS NULL as int) + cast(f."') || '" IS NULL as int)) as sum_nulls from public."'|| tab_name ||'" as f; ' into built_query | |
from information_schema.columns | |
where table_name = tab_name | |
group by table_name; | |
RETURN query EXECUTE built_query; | |
END; $$; | |
SELECT query_builder('table_name') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment