#50882·supabase

fix(pg-meta): schemas.update and schemas.remove DO blocks fail when a name contains "$$"

Author: Dextheking1Created Sep 24, 2026Updated Sep 28, 2026
Labelspr-openedexternal-issuepostgres

Summary

pgMeta.schemas.update and pgMeta.schemas.remove build DO $$ ... $$; blocks that interpolate user-controlled schema names (and the new name / new owner) via literal() into the block body. When any of those values contains the literal byte sequence $$, PostgreSQL's dollar-quote parser treats the first $$ it sees in the body as the closing delimiter, the body is truncated, and the statement fails with a syntax error at or near "..." error.

This is the same class of bug as the sibling paths already reported for table-privileges (#49523), column-privileges (#49588), roles (#49600), foreign-tables (#49603), publications (#49605), tables + columns (#49688), and functions (#50878): packages/pg-meta/src/pg-meta-schemas.ts (update rename/owner block and remove block) is the remaining file that interpolates values into a $$-quoted body.

Repro

sql
create schema "weird$$name";
-- what pgMeta.schemas.update({ name: 'weird$$name' }, { name: 'weird$$name' })
-- generates on master today:
do $$
declare
  id oid := 'weird$$name'::regnamespace;
  ...
end
$$;
-- ERROR: syntax error at or near "name"

The outer $$ closes at the $$ inside 'weird$$name', so the rest of the body is parsed as separate statements and the query fails. The same breakage applies to schemas.update with an owner containing $$ and to schemas.remove for a schema named weird$$name.

Verified by rendering the generated SQL and parsing it with a real PostgreSQL parser: the three cases above fail on pristine code and a control case with normal names parses fine.

Expected

The DO block should pick a delimiter that is absent from every value that flows into the body, just like the sibling fixes do. A schema named weird$$name should round-trip cleanly through schemas.update and schemas.remove.

Suggested fix

Add a per-file getDoBlockDelimiter(values: string[]) helper in pg-meta-schemas.ts (mirroring the helpers shipped in the sibling files) and substitute its return value for the literal $$ opener / closer in both DO blocks. For the update path, values = [name, newName, owner]; for the remove path, values = [name].