pgschema icon indicating copy to clipboard operation
pgschema copied to clipboard

Force qualified names in dump

Open bndbsh opened this issue 10 months ago • 5 comments

Is it possible to force dump to qualify all table references? This would make the output easier to integrate in workflows that expect a specific schema to be used. It would also make the output more consistent as e.g. functions that reference tables in a qualified way still do so in the dump.

bndbsh avatar Jan 21 '26 13:01 bndbsh

We try to be intelligent about dumping a schema-agnostic dump so that it can be used to diff between different pg schemas.

Do you have a particular example to show what you'd like?

tianzhou avatar Jan 21 '26 15:01 tianzhou

We have a database where we use qualified names in functions so those end up in the dump as well, however the table definitions are not qualified. It wouldn't be meaningful to retarget these to a different schema. In addition, we also use qualified names in migrations and queries. This makes directly integrating pgschema into our workflow tricky since we need to postprocess any dump to make it directly usable. I realize pgschema can qualify names in migrations, however we'd like to also use the dump for other purposes (setting up test instances, sqlc-style codegen, etc). It seems that qualifying the dumps from pgschema is the simplest solution, though I'm open to ideas.

bndbsh avatar Jan 23 '26 16:01 bndbsh

Would prepend SET search_path when using the dump work?

SET search_path TO public; \i pgschema_dump.sql

This makes all unqualified names resolve to your target schema.

tianzhou avatar Jan 28 '26 15:01 tianzhou

This makes all unqualified names resolve to your target schema.

Wouldn't that make them resolve to public?

To be clear the issue is with what I'm feeding the schema to (in this case sqlc),as setting the search path doesn't help. Loading the dump into a real postgres instance isn't an issue as that will respect search_path, but sqlc seems to get confused. For the moment I'm working around the issue downstream of pgschema since it's not an issue with the dump, although being able to force a qualifier would make it easier to integrate in this setup.

bndbsh avatar Feb 09 '26 12:02 bndbsh

Tried to strip qualifier from function body. Let's see how that goes.

tianzhou avatar Feb 16 '26 18:02 tianzhou