graphql-engine/server/src-rsr/pg_metadata_lib.sql
Philip Lykke Carlsen e1918adb52 Replace "identity column" with "column mutability" data for all backends
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3373
GitOrigin-RevId: bf08cc9008a4b0b3ece4952528c15c45e57fc74c
2022-02-03 14:15:35 +00:00

50 lines
2.0 KiB
PL/PgSQL

CREATE SCHEMA IF NOT EXISTS hdb_lib;
CREATE OR REPLACE FUNCTION
hdb_lib.pg_attidentity()
RETURNS TABLE (attrelid oid, attname name, attnum smallint, attidentity char) AS $$
BEGIN
IF current_setting('server_version_num')::int >= 100000
THEN RETURN QUERY
SELECT a.attrelid, a.attname, a.attnum, a.attidentity::char
FROM pg_catalog.pg_attribute a;
ELSE
-- Always return attidentity = '', indicating that the column is not an
-- identity column.
RETURN QUERY
SELECT a.attrelid, a.attname, a.attnum, ''::char as attidentity
FROM pg_catalog.pg_attribute a;
END IF;
END;
$$ LANGUAGE plpgsql;
COMMENT ON FUNCTION hdb_lib.pg_attidentity() IS
'The column "pg_catalog.pg_attribute(attidentity)" was only introduced in PG 10,
along with with the introduction of identity columns.
This function provides the "attidentity" column in a cross-version compatible way.
See https://www.postgresql.org/docs/10/catalog-pg-attribute.html for details.
';
CREATE OR REPLACE FUNCTION
hdb_lib.pg_attgenerated()
RETURNS TABLE (attrelid oid, attname name, attnum smallint, attgenerated char) AS $$
BEGIN
IF current_setting('server_version_num')::int >= 120000
THEN RETURN QUERY
SELECT a.attrelid, a.attname, a.attnum, a.attgenerated::char
FROM pg_catalog.pg_attribute a;
ELSE
-- Always return attgenerated = '', indicating that the column is not a
-- generated column.
RETURN QUERY
SELECT a.attrelid, a.attname, a.attnum, ''::char as attgenerated
FROM pg_catalog.pg_attribute a;
END IF;
END;
$$ LANGUAGE plpgsql;
COMMENT ON FUNCTION hdb_lib.pg_attgenerated() IS
'The column "pg_catalog.pg_attribute(attgenerated)" was only introduced in PG 12,
along with the introduction of generated columns.
This function provides the "attgenerated" column in a cross-version compatible way.
See https://www.postgresql.org/docs/12/catalog-pg-attribute.html for details.
';