Scan relation row types as STRUCT (not VARCHAR)#475
Merged
Conversation
Every PG relation (table/view/matview/foreign/partitioned) has an implicit
row type with typtype='c'. The existing composite-type discovery query
filtered them out with pg_class.relkind='c', so a column whose declared
type was a relation row type (e.g. a view that aliases a table as a row
variable) fell back to VARCHAR even though the binary and text readers
already handle STRUCT recursively.
Widen the relkind filter to IN ('c','r','v','m','f','p') and add the
required attnum > 0 / NOT attisdropped filters so we skip system and
dropped columns on physical relations.
staticlibs
approved these changes
May 25, 2026
Member
staticlibs
left a comment
There was a problem hiding this comment.
Thanks for the PR! It looks good to me.
adamchol
pushed a commit
to dialohq/duckdb-postgres
that referenced
this pull request
May 26, 2026
Follow-up to duckdb#474 / duckdb#475. After PR duckdb#475, row types of relations are discovered and registered under their own schema, so the in-schema case works. But when a relation in schema B has a column whose type is the row type of a relation in schema A, PostgresUtils::TypeToLogicalType still looked up the type entry against the relation's schema (B). It finds nothing there and falls back to VARCHAR. Plumb the type's own namespace through PostgresTypeData. The two discovery queries now join pg_namespace on pg_type.typnamespace and expose nspname as the type's schema, and TypeToLogicalType uses Catalog::GetSchema to resolve the lookup against that schema when it differs from the relation's own. Extend test/sql/storage/attach_types_table_row.test with a cross- schema view and table; the existing test put both ends in the same schema, which is why this slipped through.
adamchol
added a commit
to dialohq/duckdb-postgres
that referenced
this pull request
May 26, 2026
Follow-up to duckdb#474 / duckdb#475. After PR duckdb#475, row types of relations are discovered and registered under their own schema, so the in-schema case works. But when a relation in schema B has a column whose type is the row type of a relation in schema A, PostgresUtils::TypeToLogicalType still looked up the type entry against the relation's schema (B). It finds nothing there and falls back to VARCHAR. Plumb the type's own namespace through PostgresTypeData. The two discovery queries now join pg_namespace on pg_type.typnamespace and expose nspname as the type's schema, and TypeToLogicalType uses Catalog::GetSchema to resolve the lookup against that schema when it differs from the relation's own. Extend test/sql/storage/attach_types_table_row.test with a cross- schema view and table; the existing test put both ends in the same schema, which is why this slipped through.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #474
This PR allows to use composite types from views/materialized views etc. Until now it was only possible for tables.
In postgres:
In duckdb: