如何使用sqitch-postgresql验证alter列数据类型更改?
我正在进行以下如何使用sqitch-postgresql验证alter列数据类型更改?,postgresql,database-migration,postgresql-10,sqitch,Postgresql,Database Migration,Postgresql 10,Sqitch,我正在进行以下deploy更改。将时间戳列的值更改为时间戳 -- Alter the is_deleted flags to be timestamp with time zone alter table source_meta.sources alter column is_deleted set data type timestamptz using is_deleted at time zone 'UTC'; alter table source_meta.se
deploy
更改。将时间戳
列的值更改为时间戳
-- Alter the is_deleted flags to be timestamp with time zone
alter table source_meta.sources alter column is_deleted set data type timestamptz
using
is_deleted at time zone 'UTC';
alter table source_meta.series alter column is_deleted set data type timestamptz
using
is_deleted at time zone 'UTC';
如果数据类型未更改,如何编写将出错的验证脚本
还需要有关还原
的帮助,以从时间戳中删除时区
SELECT 1/count(*)
FROM information_schema.columns
WHERE table_name = 'sources'
and column_name = 'is_deleted'
and data_type = 'timestamp with time zone';
这是我能想到的,但我不是专家,我不确定这是做这件事的方式还是愚蠢的方式
如果没有找到符合该条件的行,则会抛出一个除法为零的错误。您的解决方案在我看来相当不错,@nackjicholson。如果您想要更详细的错误消息,可以将其包装在DO
块中并引发错误:
DO $$
BEGIN
PERFORM TRUE
FROM information_schema.columns
WHERE table_name. = 'sources'
AND column_name = 'is_deleted'
AND data_type = 'timestamp with time zone';
IF NOT FOUND THEN
RAISE EXCEPTION 'sources.is_deleted type is not timestamptz';
END IF;
END;
$$;
谢谢你的帮助,大卫!