Skip to content

Fix pg_catalog compliance for strict PG wire clients#3

Merged
rustyconover merged 1 commit into
haybarnfrom
fix/pg-catalog-compliance-tier123
Jun 8, 2026
Merged

Fix pg_catalog compliance for strict PG wire clients#3
rustyconover merged 1 commit into
haybarnfrom
fix/pg-catalog-compliance-tier123

Conversation

@rustyconover

Copy link
Copy Markdown
Contributor

Summary

Closes a set of pg_catalog non-compliance gaps that break strict PostgreSQL wire-protocol clients — confirmed against Npgsql 4.0.12 / 4.1.12 / 8.0.6 (the .NET driver behind PowerBI) and BI tools (DBeaver, pgAdmin) connecting through vgi-postgresql. All changes are SQL view / macro literals — no C++ or parser changes.

1. pg_type / pg_namespace NOT-NULL + schema compliance (default_views.cpp)

PostgreSQL declares typnotnull, typdelim, typinput, typoutput, typreceive, typsend as NOT NULL. The view hardcoded them NULL, so Npgsql's type loader (which reads every column as a non-nullable string) threw on connect. Now: typnotnull=false, typdelim=',', typinput/typoutput/typreceive/typsend=0.

  • The base UNION ALL branch emitted a NULL oid for types map_to_pg_oid can't represent; those rows are now filtered out.
  • Built-in types' typnamespace now routes to pg_catalog (via the internal flag); user enums keep their real schema.
  • pg_namespace drops the now-redundant type-host clause.

2. Twelve standard catalog tables (default_views.cpp)

pg_roles (one synthetic superuser), pg_extension, pg_foreign_data_wrapper, pg_foreign_server, pg_shdescription, pg_conversion, pg_aggregate, pg_trigger, pg_rewrite, pg_inherits, pg_language, pg_range — mostly empty stubs carrying the columns clients join/select.

3. Catalog functions (default_functions.cpp)

pg_relation_size/pg_total_relation_size/pg_table_size/pg_indexes_size/pg_stat_get_numscans (-> 0), pg_get_indexdef/pg_get_triggerdef/pg_get_ruledef (-> ''), pg_get_userbyid (-> 'postgres'), pg_encoding_to_char (-> 'UTF8'), and a 3-arg pg_get_expr.

Tests

[pg_catalog] -> 489 assertions / 19 cases pass; [catalog] -> 1554 / 56 pass. New pg_catalog_compat.test plus extended pg_type.test and updated sqlalchemy.test.

🤖 Generated with Claude Code

Three categories of pg_catalog gaps that break strict PostgreSQL drivers
(Npgsql 4.0/4.1/8.0, used by PowerBI/.NET) and BI tools (DBeaver, pgAdmin):

1. pg_type / pg_namespace NOT NULL + schema compliance (default_views.cpp)
   PostgreSQL declares typnotnull/typdelim/typinput/typoutput/typreceive/
   typsend NOT NULL; the view hardcoded them NULL, so Npgsql's type loader
   (reads every column as a non-nullable string) crashed on connect. Now:
   typnotnull=false, typdelim=',', typinput/typoutput/typreceive/typsend=0.
   The base branch also emitted NULL oids for unmappable types; those rows
   are now filtered out (oid is NOT NULL in PG, and a NULL oid breaks driver
   type-loading). Built-in types' typnamespace now routes to pg_catalog
   (via the `internal` flag) so a driver joining typnamespace->pg_namespace
   resolves them as pg_catalog.<type>, matching its built-in readers; user
   enums keep their real schema. pg_namespace drops the now-redundant
   type-host clause.

2. Twelve standard catalog tables (default_views.cpp)
   pg_roles (one synthetic superuser), pg_extension, pg_foreign_data_wrapper,
   pg_foreign_server, pg_shdescription, pg_conversion, pg_aggregate,
   pg_trigger, pg_rewrite, pg_inherits, pg_language, pg_range. Mostly empty
   stubs carrying the columns clients join/select, so introspection queries
   parse and resolve to zero rows instead of erroring on a missing table.

3. Catalog functions (default_functions.cpp)
   pg_relation_size/pg_total_relation_size/pg_table_size/pg_indexes_size/
   pg_stat_get_numscans (->0), pg_get_indexdef/pg_get_triggerdef/
   pg_get_ruledef (->''), pg_get_userbyid (->'postgres'),
   pg_encoding_to_char (->'UTF8'), and a 3-arg pg_get_expr (pretty flag).

Tests: pg_type non-null columns + no-NULL-oid + pg_catalog typnamespace
assertions; a new pg_catalog_compat.test covering every added table and
function; sqlalchemy.test updated for built-ins-in-pg_catalog.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@rustyconover
rustyconover merged commit eed019e into haybarn Jun 8, 2026
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