Problem: sqlc can't recognize PostgreSQL data types numeric and decimal with the default database driver package database/sql, it makes them string.
Using the PostgreSQL driver pgx, Sqlc can make them pgtype.Numeric type, but still can't overrides them to float64:
version: "2"
sql:
- engine: "postgresql"
queries: "db/query"
schema: "db/schema"
gen:
go:
package: "db"
out: "db/sqlc"
sql_package: "pgx/v5"
emit_json_tags: true
emit_interface: true
emit_empty_slices: true
overrides:
- db_type: "numeric"
go_type: "float64"
- db_type: "decimal"
go_type: "float64"
Have to change gptye.Numeric to float after the codes are generated:
# manually change pgtype.Numeric to float64 sed -i 's/pgtype.Numeric/float64/g' db/sqlc/*.go goimports -w db/sqlc/*.go gofmt -w db/sqlc/*.go sed -i 's/\t/ /g' db/sqlc/*.go

浙公网安备 33010602011771号