pgschema icon indicating copy to clipboard operation
pgschema copied to clipboard

types created in schema cause reference errors in planning

Open whoward opened this issue 1 year ago • 1 comments

Given the following database definition:

create schema some_schema;

create type some_schema.some_type as enum ('value1', 'value2', 'value3');

create type some_schema.some_other_type as (
  name text,
  type some_schema.some_type
);

create function some_schema.some_function(type some_schema.some_type)
returns void as $$
BEGIN
  RAISE NOTICE 'Hello, %!', type;
END;
$$ language plpgsql;

pgschema dump --schema some_schema produces the following output:

--
-- pgschema database dump
--

-- Dumped from database version PostgreSQL 17.0
-- Dumped by pgschema version 1.4.0


--
-- Name: some_other_type; Type: TYPE; Schema: -; Owner: -
--

CREATE TYPE some_other_type AS (name text, type some_schema.some_type);

--
-- Name: some_type; Type: TYPE; Schema: -; Owner: -
--

CREATE TYPE some_type AS ENUM (
    'value1',
    'value2',
    'value3'
);

--
-- Name: some_function; Type: FUNCTION; Schema: -; Owner: -
--

CREATE OR REPLACE FUNCTION some_function(
    type some_schema.some_type
)
RETURNS void
LANGUAGE plpgsql
SECURITY INVOKER
VOLATILE
AS $$
BEGIN
  RAISE NOTICE 'Hello, %!', type;
END;
$$;

But when fed back into pgschema plan we get this error:

Error: failed to apply desired state to embedded PostgreSQL: failed to apply schema SQL: ERROR: type "some_schema.some_type" does not exist (SQLSTATE 42704)

Unfortunately this seems like the opposite of our previous problems where we now don't want certain things fully qualified 🤣. This could probably be solved by conditionally fully qualifying the referenced object or perhaps looking into multi-schema dumping and planning as suggested in #122

whoward avatar Oct 23 '25 15:10 whoward

very nice! i checked and this works well. Thanks!

whoward avatar Nov 04 '25 16:11 whoward