Move catalog missing column check into separate file

This commit is contained in:
Sven Klemm 2020-04-20 23:37:24 +02:00 committed by Sven Klemm
parent ed3eda2ceb
commit 8804b57cfb
2 changed files with 37 additions and 31 deletions

View File

@ -0,0 +1,36 @@
-- This file and its contents are licensed under the Apache License 2.0.
-- Please see the included NOTICE for copyright information and
-- LICENSE-APACHE for a copy of the license.
--PG11 added an optimization where columns that were added by
--an ALTER TABLE that had a DEFAULT value did not cause a table re-write.
--Instead, those columns are filled with the default value on read.
--But, this mechanism does not apply to catalog tables and does
--not work with our catalog scanning code.
--Thus make sure all catalog tables do not have this enabled (a.atthasmissing == false)
CREATE OR REPLACE FUNCTION timescaledb_catalog_has_no_missing_columns()
RETURNS VOID LANGUAGE PLPGSQL STABLE AS
$BODY$
DECLARE
cnt INTEGER;
rel_names TEXT;
BEGIN
SELECT count(*), string_agg(c.relname,' ;')
FROM pg_namespace n
INNER JOIN pg_class c ON (c.relnamespace = n.oid)
INNER JOIN pg_attribute a ON attrelid=c.oid
WHERE a.attnum >= 0 AND
(n.nspname='_timescaledb_catalog' OR n.nspname = '_timescaledb_config' OR
n.nspname='_timescaledb_internal')
AND a.atthasmissing
INTO STRICT cnt, rel_names;
IF cnt != 0 THEN
RAISE EXCEPTION 'Some catalog tables were altered without a table re-write: %', rel_names;
END IF;
END;
$BODY$;
SELECT timescaledb_catalog_has_no_missing_columns();

View File

@ -3,35 +3,5 @@
-- LICENSE-APACHE for a copy of the license.
\ir post.v3.sql
\ir catalog_missing_columns.sql
--PG11 added an optimization where columns that were added by
--an ALTER TABLE that had a DEFAULT value did not cause a table re-write.
--Instead, those columns are filled with the default value on read.
--But, this mechanism does not apply to catalog tables and does
--not work with our catalog scanning code.
--Thus make sure all catalog tables do not have this enabled (a.atthasmissing == false)
CREATE OR REPLACE FUNCTION timescaledb_catalog_has_no_missing_columns()
RETURNS VOID LANGUAGE PLPGSQL STABLE AS
$BODY$
DECLARE
cnt INTEGER;
rel_names TEXT;
BEGIN
SELECT count(*), string_agg(c.relname,' ;')
FROM pg_namespace n
INNER JOIN pg_class c ON (c.relnamespace = n.oid)
INNER JOIN pg_attribute a ON attrelid=c.oid
WHERE a.attnum >= 0 AND
(n.nspname='_timescaledb_catalog' OR n.nspname = '_timescaledb_config' OR
n.nspname='_timescaledb_internal')
AND a.atthasmissing
INTO STRICT cnt, rel_names;
IF cnt != 0 THEN
RAISE EXCEPTION 'Some catalog tables were altered without a table re-write: %', rel_names;
END IF;
END;
$BODY$;
SELECT timescaledb_catalog_has_no_missing_columns();