Skip to content

docs: clarify db_type override must use the canonical parser type name - #4620

Open
shaikn6 wants to merge 1 commit into
sqlc-dev:mainfrom
shaikn6:docs/db-type-canonical-name
Open

shaikn6 wants to merge 1 commit into
sqlc-dev:mainfrom
shaikn6:docs/db-type-canonical-name

Conversation

@shaikn6

@shaikn6 shaikn6 commented Sep 14, 2026

Copy link
Copy Markdown

What

Document that db_type overrides must use the canonical parser type name, not the type name written in the schema.

Why / evidence

Issue #2762 asks for the db_type values 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 to Override.MatchesColumn in internal/codegen/golang/opts/override.go, which does an exact string match (o.DBType == columnType) against sdk.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 the db_type bullet in docs/howto/overrides.md giving the concrete INTEGER -> pg_catalog.int4 example and stating explicitly that a mismatched db_type fails silently (no error).

Verified

Built sqlc from this branch (go build -o /tmp/sqlc-repro ./cmd/sqlc/) and ran generate against a minimal schema with an INTEGER NOT NULL column bar:

  • db_type: "integer" -> generated Bar int32 (override silently ignored)
  • db_type: "pg_catalog.int4" -> generated Bar string (override applied)

This confirms the exact behavior documented in the callout.

Fixes #2762

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
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.

Document db_type for type overrides

1 participant