Skip to content

dump emits wrong LANGUAGE for overloaded functions (plpgsql dumped as sql) #368

@dilame

Description

@dilame

Summary

pgschema dump assigns the wrong LANGUAGE to overloaded functions. When two functions share the same name but have different languages (e.g., one sql and one plpgsql), the dump may emit the plpgsql overload with LANGUAGE sql, making the dump non-replayable.

Environment

  • pgschema: 1.7.2
  • PostgreSQL: 18.2

Minimal repro

CREATE SCHEMA s;

-- Overload 1: SQL
CREATE FUNCTION s.provide_tx(VARIADIC p_txs text[])
RETURNS void LANGUAGE sql AS $$ SELECT 1; $$;

-- Overload 2: plpgsql
CREATE FUNCTION s.provide_tx(p_id uuid)
RETURNS void LANGUAGE plpgsql AS $$
    # variable_conflict use_column
BEGIN
    RAISE NOTICE '%', p_id;
END;
$$;
pgschema dump --schema s --db <db> --user <user>

Expected

Both overloads dumped with their correct LANGUAGE:

  • provide_tx(VARIADIC text[])LANGUAGE sql
  • provide_tx(uuid)LANGUAGE plpgsql

Actual

The plpgsql overload is emitted with LANGUAGE sql:

CREATE OR REPLACE FUNCTION provide_tx(
    p_id uuid
)
RETURNS void
LANGUAGE sql    -- ← wrong, should be plpgsql
VOLATILE
AS $$
    # variable_conflict use_column   -- ← syntax error in sql context
BEGIN
    ...

This causes a syntax error when replaying the dump (plan or apply):

ERROR: syntax error at or near "#" (SQLSTATE 42601)

Impact

  • pgschema plan cannot produce a valid plan for any schema containing overloaded functions with mixed languages
  • pgschema dump output is not idempotent — cannot be re-applied

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions