Function COMMENT is lost when a function is recreated via DROP + CREATE
When a function change is planned as DROP FUNCTION + CREATE FUNCTION (e.g. a return type change), the plan does not re-emit COMMENT ON FUNCTION. The DROP removes the comment, so after one apply the comment is gone, and a second plan shows a diff that only adds it back.
Per #240, a non-empty plan right after apply is a bug, so filing this.
Reproduction (pgschema 1.13.4, PostgreSQL 16)
v1.sql:
CREATE FUNCTION f(x integer) RETURNS integer LANGUAGE sql IMMUTABLE AS $$ SELECT x $$;
COMMENT ON FUNCTION f(integer) IS 'my comment';
v2.sql (only the return type changes):
CREATE FUNCTION f(x integer) RETURNS bigint LANGUAGE sql IMMUTABLE AS $$ SELECT x::bigint $$;
COMMENT ON FUNCTION f(integer) IS 'my comment';
Steps:
-
pgschema apply --file v1.sql(comment is set) -
pgschema plan --file v2.sqloutputs:DROP FUNCTION IF EXISTS f(integer); CREATE OR REPLACE FUNCTION f( x integer ) RETURNS bigint LANGUAGE sql IMMUTABLE AS $$ SELECT x::bigint $$;No
COMMENT ON FUNCTIONin the plan. -
pgschema apply --file v2.sql, thenSELECT obj_description('f(integer)'::regprocedure, 'pg_proc')returnsNULL. -
pgschema plan --file v2.sqlagain:Plan: 1 to modify. ... COMMENT ON FUNCTION f(integer) IS 'my comment';
Expected
The plan in step 2 includes COMMENT ON FUNCTION f(integer) IS 'my comment'; after the CREATE, so one apply converges and the next plan reports no changes.
Notes
- An external plan database (
--plan-host, plainpostgres:16) was used for both plan and apply. CREATE OR REPLACEcases (body-only changes) keep the comment, since PostgreSQL does not drop it there. Only theDROP+CREATEpath is affected.