pgschema
pgschema copied to clipboard
references to functions in generated column definitions should be fully qualified
Given the following database definition:
create function public.extract_domain(website text) returns text
LANGUAGE sql IMMUTABLE
AS $$
SELECT CASE WHEN website = ''
THEN NULL
ELSE SUBSTRING(website FROM '(?:.*://)?(?:www\.)?([^/?#]*)')
END
$$;
create schema some_schema;
create table some_schema.some_table(id serial primary key, full_domain text, domain text generated always as (public.extract_domain(full_domain)) stored);
pgschema dump produces:
--
-- pgschema database dump
--
-- Dumped from database version PostgreSQL 17.0
-- Dumped by pgschema version 1.5.0
--
-- Name: some_table; Type: TABLE; Schema: -; Owner: -
--
CREATE TABLE IF NOT EXISTS some_table (
id SERIAL,
full_domain text,
domain text GENERATED ALWAYS AS (extract_domain(full_domain)) STORED,
CONSTRAINT some_table_pkey PRIMARY KEY (id)
);
When fed back into pgschema plan we get the following error:
Error: failed to apply desired state: failed to apply schema SQL to temporary schema pgschema_tmp_20251209_122803_94ff2f7f: ERROR: function extract_domain(text) does not exist (SQLSTATE 42883)
This happens because when loading the dump the function reference cannot be resolved within the search path that pgschema plan applies.
apologies for the delay but i've just checked and this works well now - thanks!