Created
October 19, 2014 18:42
-
-
Save happysundar/79336ddd05da199450db to your computer and use it in GitHub Desktop.
Get all the column names of a table...
This file contains hidden or 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
DROP FUNCTION IF EXISTS get_column_names_csv( TEXT, TEXT ) CASCADE; | |
CREATE OR REPLACE FUNCTION | |
get_column_names_csv(input_schema_name TEXT, input_table_name TEXT) | |
RETURNS SETOF TEXT IMMUTABLE | |
AS $$ | |
BEGIN | |
RETURN QUERY | |
WITH T1 AS ( | |
SELECT column_name | |
FROM rovi.information_schema.columns | |
WHERE | |
table_name = lower(input_table_name) AND table_schema = lower(input_schema_name) | |
AND NOT (ordinal_position = 1 AND column_default NOTNULL) | |
) | |
SELECT string_agg(column_name, ',') | |
FROM T1; | |
END | |
$$ LANGUAGE plpgsql; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment