Skip to content

Inspector/IR should preserve schema identity for type references (enable --qualify-schema for types) #493

Description

@tianzhou

Follow-up from PR #492 (dump --qualify-schema).

--qualify-schema forces full schema qualification for object identifiers (table/view/index/sequence/type/function/procedure/policy names, and ON / REFERENCES / OWNED BY / COMMENT targets). That covers the reserved-word/ambiguity class from #320.

It does not qualify same-schema type references — column types, composite attribute types, function/procedure parameter & return types, aggregate state/transition types, and domain base types. The render-side helper (stripSchemaPrefixMode) can only strip a target-schema prefix; it cannot add one, because the IR stores same-schema user-defined types as bare strings.

Root cause is in the inspector queries (ir/queries/queries.sql), e.g. the column resolved_type CASE emits bare dt.typname when dn.nspname = c.table_schema, and domain base_type uses format_type(...) which is search-path-relative. Cross-schema type references already arrive qualified and are preserved.

Proposed work

  • Have the inspector/IR preserve the schema of user-defined types alongside the type name (or always emit a qualified form) for: column types, composite attribute types, domain base types, function/procedure params + returns, aggregate state types.
  • Add a render mode that qualifies those type references when --qualify-schema is set, mirroring the object-identifier behavior.
  • Expect broad testdata fixture churn; gate carefully so default (smart-qualification) output stays byte-identical.

Out of scope

  • Free-form expression text (view bodies, policy USING/CHECK, trigger function bodies) — qualifying identifiers inside arbitrary SQL needs real parsing and is intentionally left as-is.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Fields

No fields configured for Feature.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions