pgschema
pgschema copied to clipboard
Constraint triggers cause failure in dump
Continuing on with #59 we also found that constraint trigger causes pgschema to fail dumping entirely with the following error message:
Error: failed to build IR: table details: sql: Scan error on column index 4, name "column_name": converting NULL to string is unsupported
Here's an example trigger definition which causes this to occur:
CREATE TABLE public.products (
id SERIAL PRIMARY KEY,
product_code TEXT NOT NULL UNIQUE,
name TEXT NOT NULL,
price NUMERIC(10, 2)
);
CREATE OR REPLACE FUNCTION public.raise_immutable_product_code()
RETURNS TRIGGER
LANGUAGE plpgsql
AS $$
BEGIN
RAISE EXCEPTION 'product_code is immutable and cannot be changed';
RETURN NULL;
END;
$$;
CREATE CONSTRAINT TRIGGER
enforce_product_code_immutable_tr
AFTER UPDATE OF product_code
ON public.products
NOT DEFERRABLE
INITIALLY IMMEDIATE
FOR EACH ROW WHEN ((old.product_code <> new.product_code))
EXECUTE FUNCTION public.raise_immutable_product_code();
Tested this on PostgreSQL 17
thanks for the quick turnaround! fix is working great!