non-primitive types should be fully qualified in dumps to avoid planning errors
Given the following database definition:
create extension citext with schema public;
create table some_table (id bigint primary key, fqdn citext not null);
pgschema dump produces:
--
-- pgschema database dump
--
-- Dumped from database version PostgreSQL 17.0
-- Dumped by pgschema version 1.4.1
--
-- Name: some_table; Type: TABLE; Schema: -; Owner: -
--
CREATE TABLE IF NOT EXISTS some_table (
id bigint,
fqdn citext NOT NULL,
CONSTRAINT some_table_pkey PRIMARY KEY (id)
);
And when fed back into pgschema plan using an external plan database which has the citext extension installed we get the following error:
Error: failed to apply desired state: failed to apply schema SQL to temporary schema pgschema_tmp_20251104_115815_ad7ea0a7: ERROR: type "citext" does not exist (SQLSTATE 42704)
From the postgres logs I can see that pgschema is setting the schema search path to the temporary schema that is installed:
2025-11-04 11:58:15.669 EST [27177] LOG: statement: CREATE SCHEMA IF NOT EXISTS "pgschema_tmp_20251104_115815_ad7ea0a7"
2025-11-04 11:58:15.669 EST [27177] LOG: statement: SET search_path TO "pgschema_tmp_20251104_115815_ad7ea0a7"
2025-11-04 11:58:15.669 EST [27177] LOG: statement: --
-- pgschema database dump
--
-- Dumped from database version PostgreSQL 17.0
-- Dumped by pgschema version 1.4.1
--
-- Name: some_table; Type: TABLE; Schema: -; Owner: -
--
CREATE TABLE IF NOT EXISTS some_table (
id bigint,
fqdn citext NOT NULL,
CONSTRAINT some_table_pkey PRIMARY KEY (id)
);
2025-11-04 11:58:15.669 EST [27177] ERROR: type "citext" does not exist at character 245
When the public schema is not in the search_path postgres doesn't know how to resolve the citext type that is defined in the public schema.
I believe the correct way to handle this might be to fully qualify non-standard types when dumping, which would result in the type being dumped as public.citext which should allow postgres to resolve the type regardless to what the search_path is set to.
NOTE: while I'm using an extension in this example I believe this happens for any type that is not defined within the current schema, so this example could probably be simplified more.
Hey @tianzhou, I've tested and this does seem to work for custom types across schemas but does not seem to work for types defined in extensions unfortunately. I'm not sure what the difference is but the original example described still seems to be failing.
Hey @tianzhou
Sorry I still can't get this case to work. pgschema dump still outputs
--
-- pgschema database dump
--
-- Dumped from database version PostgreSQL 17.0
-- Dumped by pgschema version 1.4.1
--
-- Name: some_table; Type: TABLE; Schema: -; Owner: -
--
CREATE TABLE IF NOT EXISTS some_table (
id bigint,
fqdn citext NOT NULL,
CONSTRAINT some_table_pkey PRIMARY KEY (id)
);
This dump doesn't work when fed back into the plan because SET search_path TO "pgschema_tmp_20251106_115546_62917b38" is executed before the dump query is executed.
@whoward pls give me some extra time, it's a more complicated case to address.
Hello Tianzhou I'm also getting errors on plan command which are related to CREATE TYPE Error: failed to apply desired state: failed to apply schema SQL to temporary schema pgschema_tmp_20251106_122150_b45828f2: ERROR: type "some_type_name" does not exist (SQLSTATE 42704)
I was thinking that maybe it is related to the searchpath. Just out of curiosity, I tried restoring the dump file created by pgschema in a new database(single/multifile) and got alot of "object doesn't exists" error which includes tables/functions/types.
G'day. Is this actually fixed?
Db Name: support Schema: driver_key
citext is definitely in the public schema.
Here is the output of dump:
-- pgschema database dump
-- Dumped from database version PostgreSQL 17.7 -- Dumped by pgschema version 1.6.2
CREATE TABLE IF NOT EXISTS lookup ( geotab_database_name public.citext NOT NULL, serial_number public.citext NOT NULL, id uuid DEFAULT public.uuid_generate_v1mc(), CONSTRAINT driver_key_lookup_pk PRIMARY KEY (id) ); CREATE INDEX IF NOT EXISTS lookup_geotab_database_name_idx ON lookup (lower(geotab_database_name::text)); CREATE INDEX IF NOT EXISTS lookup_serial_number_idx ON lookup USING gin (lower(serial_number::text) gin_trgm_ops);
If I run plan against it, with no schema changes I get: Error: failed to apply desired state: failed to apply schema SQL to temporary schema pgschema_tmp_20260206_155639_02f41db8: ERROR: type "public.citext" does not exist (SQLSTATE 42704)
OK, I had to manually add the following to the above for it to work. Maybe something to add to the tutorials if that's supposed to be necessary?
CREATE EXTENSION IF NOT EXISTS citext WITH SCHEMA public; CREATE EXTENSION IF NOT EXISTS "uuid-ossp" WITH SCHEMA public; CREATE EXTENSION IF NOT EXISTS pg_trgm SCHEMA public;