PLpgSQL function to find columns with only NULL values in a given table
问题 We have to find columns of a table with only NULL values. We are trying to build a plpgsql function that takes a table's name and returns the list of such columns. How to create such a function? We are using PgAdmin 1.16. 回答1: You can query the catalog table pg_attribute to get a list of columns which are not defined NOT NULL and therefore can hold NULL values: SELECT quote_ident(attname) AS column_can_be_null FROM pg_attribute WHERE attrelid = 'tbl'::regclass -- valid, visible table name AND