Skip to content

fix: resolve pg_collation error in table reflection with SQLAlchemy 2.0.45+#1393

Open
pcorpet wants to merge 2 commits intoMause:mainfrom
pcorpet:fix-collation
Open

fix: resolve pg_collation error in table reflection with SQLAlchemy 2.0.45+#1393
pcorpet wants to merge 2 commits intoMause:mainfrom
pcorpet:fix-collation

Conversation

@pcorpet
Copy link
Copy Markdown

@pcorpet pcorpet commented Mar 28, 2026

Override the _columns_query method in the DuckDB dialect to avoid querying pg_collation, which doesn't exist in DuckDB's catalog. Instead of querying pg_collation like SQLAlchemy's PostgreSQL dialect does, we return NULL for the collation field.

This fixes issue #1391 where table autoload would fail with "Catalog Error: Table with name pg_collation does not exist!" when using SQLAlchemy 2.0.45 or later.

Related to SQLAlchemy issue #6511 which introduced pg_collation queries in the column reflection process.

The fix:

  • Adds REGCLASS and OID type imports from sqlalchemy.dialects.postgresql.types
  • Implements _columns_query method that mirrors SQLAlchemy's PostgreSQL dialect
  • Modifies only the collation variable to return sql.null() instead of querying pg_collation
  • All other column reflection logic remains unchanged

Tested with:

  • Simple table autoload
  • Tables with various column types
  • Full schema reflection via metadata.reflect()

pcorpet and others added 2 commits March 28, 2026 22:09
….0.45+

Override the _columns_query method in the DuckDB dialect to avoid querying
pg_collation, which doesn't exist in DuckDB's catalog. Instead of querying
pg_collation like SQLAlchemy's PostgreSQL dialect does, we return NULL for
the collation field.

This fixes issue Mause#1391 where table autoload would fail with "Catalog Error:
Table with name pg_collation does not exist!" when using SQLAlchemy 2.0.45
or later.

Related to SQLAlchemy issue #6511 which introduced pg_collation queries in
the column reflection process.

The fix:
- Adds REGCLASS and OID type imports from sqlalchemy.dialects.postgresql.types
- Implements _columns_query method that mirrors SQLAlchemy's PostgreSQL dialect
- Modifies only the collation variable to return sql.null() instead of querying pg_collation
- All other column reflection logic remains unchanged

Tested with:
- Simple table autoload
- Tables with various column types
- Full schema reflection via metadata.reflect()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant