Open
Description
From the discussion, perhaps we also want to add functions to test whether a column is STORED or GENERATED, as well. See especially this followup with some useful catalog querying context:
-- a function for testing since pgtap doesn't have an equivalent of this
-- remove when pgtap can check for column identities
CREATE OR REPLACE FUNCTION public._get_column_identity(
p_schema VARCHAR,
p_table VARCHAR,
p_column VARCHAR
)
RETURNS CHAR AS $$
SELECT coalesce(a.attidentity, a.attgeneratd)
FROM pg_catalog.pg_attribute a
WHERE a.attrelid =
( SELECT c.oid FROM pg_catalog.pg_class c LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE n.nspname = p_schema AND c.relname = p_table )
AND a.attnum > 0
AND NOT a.attisdropped
AND a.attname = p_column
AND pg_catalog.format_type(a.atttypid, a.atttypmod) in ( 'integer', 'smallinteger', 'biginteger' )
AND a.attnotnull ;
$$ LANGUAGE SQL;