Skip to content

fix: resolve NotSupportedException for schema-qualified PostgreSQL enum types#421

Merged
doron050 merged 5 commits into
mainfrom
fix/399-postgresql-enum-support
Jul 11, 2026
Merged

fix: resolve NotSupportedException for schema-qualified PostgreSQL enum types#421
doron050 merged 5 commits into
mainfrom
fix/399-postgresql-enum-support

Conversation

@doron050

Copy link
Copy Markdown
Collaborator

Fixes #399

When a PostgreSQL column references an enum type with schema qualification (e.g., block_type public.post_block_type), sqlc sets column.Type.Schema to "public". However, ConstructEnumsLookup normalizes default schema enums under key "" (empty string), causing GetEnumType to fail the lookup and throw NotSupportedException.

Changes

  1. Drivers/NpgsqlDriver.cs — Normalize the schema name in GetEnumSchemaAndName to empty string when it matches DefaultSchema, making it consistent with ConstructEnumsLookup.

  2. unit-tests/CodegenTests/CodegenSchemaTests.cs — Added TestDefaultSchemaEnumWithSchemaQualifiedType that constructs a GenerateRequest with column.Type.Schema = "public" and asserts successful generation (was throwing before the fix).

  3. examples/config/postgresql/types/ — Added postgres_qualified_enum_types table with a column referencing public.c_enum (schema-qualified), plus INSERT/SELECT/TRUNCATE queries. This exercises the fixed code path in e2e tests.

  4. examples/Npgsql* — Regenerated all Npgsql example code to include the new model/queries.

  5. end2end/ — Added TruncatePostgresQualifiedEnumTypesAsync to both Npgsql and NpgsqlDapper tester TearDown methods.

Testing

  • All 20 unit tests pass
  • The new unit test reproduces the exact stack trace from the issue before the fix
  • The new table postgres_qualified_enum_types with public.c_enum column verifies the fix end-to-end

doron050 added 5 commits July 10, 2026 14:50
…um types

When a PostgreSQL column references an enum type with schema qualification
(e.g., `block_type public.post_block_type`), sqlc sets `column.Type.Schema`
to `public`. However, `ConstructEnumsLookup` normalizes default schema
enums under key `` (empty string), causing `GetEnumType` to fail the
lookup and throw `NotSupportedException`.

Fixed by normalizing the schema name in `GetEnumSchemaAndName` to empty
string when it matches the driver's DefaultSchema.

Changes:
- Drivers/NpgsqlDriver.cs: normalize default schema in GetEnumSchemaAndName
- unit-tests/CodegenTests/CodegenSchemaTests.cs: add failing-then-passing test
- examples/config/postgresql/types/: add schema-qualified enum table + queries
- examples/Npgsql*Example/: regenerated code with new model/queries
- end2end/: add truncation for new table in e2e TearDown
8.4.6 was removed from the MySQL CDN (404), causing Chocolatey install
to fail. 8.4.9 is the latest 8.4.x patch available.
The pinned versions 8.4.6 and 8.4.9 both fail — 8.4.6 downloads from a
dead CDN URL, and 8.4.9 doesn't exist on Chocolatey. Removing the pin
lets Chocolatey resolve the latest approved version with a valid URL.
…types table

Move c_qualified_enum (public.c_enum) into the existing
postgres_special_types table instead of a separate
postgres_qualified_enum_types table, per PR feedback.

The schema-qualified enum type is tested alongside the existing
unqualified c_enum column in the same table and its queries.
This avoids adding a new table to the schema.
@doron050 doron050 requested a review from SockworkOrange July 11, 2026 16:41
@doron050 doron050 merged commit 16b5627 into main Jul 11, 2026
6 checks passed
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.

System.NotSupportedException: has unsupported column type when trying to use with postgresql enum

2 participants