Re: ALTER SCHEMA: renaming does not update string-literal function bodies

From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: ben(at)mlabs(dot)city, pgsql-docs(at)lists(dot)postgresql(dot)org
Subject: Re: ALTER SCHEMA: renaming does not update string-literal function bodies
Date: 2026-10-09 21:22:27
Message-ID: 12030d192d4a881dff7363d035631c349a0d2514.camel@cybertec.at
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-docs

On Fri, 2026-10-09 at 19:32 +0000, PG Doc comments form wrote:
> Page: https://www.postgresql.org/docs/18/sql-alterschema.html
>
> The ALTER SCHEMA page has no Notes section, and renaming a schema has one
> consequence that is easy to miss.
>
> Objects that store parsed references follow the rename: views, functions
> with SQL-standard bodies (BEGIN ATOMIC), and privileges, including ALTER
> DEFAULT PRIVILEGES entries. Function bodies written as string constants (AS
> $$ ... $$, and every non-SQL language) are stored as text, so a
> schema-qualified reference inside them keeps the old name and fails at the
> next call. On 14.10, after ALTER SCHEMA old RENAME TO newsch, a LANGUAGE sql
> function containing SELECT count(*) FROM old.t fails with ERROR: relation
> "old.t" does not exist, while the BEGIN ATOMIC version returns the right
> count.
>
> Suggested note:
>
> "Renaming a schema does not update references to it inside function and
> procedure bodies written as string constants, since those are parsed only at
> execution time (see CREATE FUNCTION). Views and SQL-standard function bodies
> are updated automatically."

I think that would be useful information (but it would have to be worded
differently: neither views nor SQL-standard function bodies are really
updated).

However, it feels odd to document that for schemas, but not for tables, columns,
functions and all other kinds of objects. It would be even worse to document
that over and over for all the ALTER commands.

How about describing that in a generic location, so that it is clear that it
applies to all objects? I am not sure where, but perhaps some introductory
note in the "Data Definition" chapter?

Yours,
Laurenz Albe

In response to

Responses

Browse pgsql-docs by date

  From Date Subject
Next Message Tom Lane 2026-10-09 21:36:06 Re: ALTER SCHEMA: renaming does not update string-literal function bodies
Previous Message David G. Johnston 2026-10-09 21:07:37 Re: ALTER SCHEMA: renaming does not update string-literal function bodies