Conversation
db_type overrides are matched against the canonical type name the Postgres parser assigns to a column (e.g. pg_catalog.int4), not the type name written in the schema (e.g. integer). A mismatch fails silently: no error, no override applied. Confirmed by building sqlc and generating with db_type: "integer" (no-op) vs db_type: "pg_catalog.int4" (applied) against an INTEGER column. Fixes sqlc-dev#2762
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.
What
Document that
db_typeoverrides must use the canonical parser type name, not the type name written in the schema.Why / evidence
Issue #2762 asks for the
db_typevalues sqlc actually expects to be documented, referencing the confusion in #421 (db_type: "integer"doesn't work;db_type: "pg_catalog.int4"does). I traced this toOverride.MatchesColumnininternal/codegen/golang/opts/override.go, which does an exact string match (o.DBType == columnType) againstsdk.DataType(col.Type)-- the canonical type the Postgres parser assigns to the column -- not the raw schema type name. A mismatch produces no error and no override; it silently falls back to the default Go type. The existing docs only say "you must use pg_catalog-prefixed names where available" with no concrete example or warning that the failure is silent.Change
Added a
[!WARNING]callout under thedb_typebullet indocs/howto/overrides.mdgiving the concreteINTEGER->pg_catalog.int4example and stating explicitly that a mismatcheddb_typefails silently (no error).Verified
Built sqlc from this branch (
go build -o /tmp/sqlc-repro ./cmd/sqlc/) and rangenerateagainst a minimal schema with anINTEGER NOT NULLcolumnbar:db_type: "integer"-> generatedBar int32(override silently ignored)db_type: "pg_catalog.int4"-> generatedBar string(override applied)This confirms the exact behavior documented in the callout.
Fixes #2762