SQLC - Problem: can't recognize the numeric data type in PostgreSQL

发布时间 2023-11-29 08:43:21作者: ZhangZhihuiAAA

Problem: sqlc can't recognize the numeric data type in PostgreSQL, it makes it string. The default sql_package database/sql can't overwrite the "numeric" database type with go type "float64".

sqlc.yaml:

version: "2"
sql:
  - engine: "postgresql"
    queries: "db/sqlc/query"
    schema: "db/schema/0001_create_tables.sql"
    gen:
      go:
        package: "db"
        out: "./db/sqlc"
        emit_json_tags: true
        overrides:
          - db_type: "numeric"
            go_type: 
              type: "float64"

 

Resolution: change the sql_package to pgx:

version: "2"
sql:
  - engine: "postgresql"
    queries: "db/sqlc/query"
    schema: "db/schema/0001_create_tables.sql"
    gen:
      go:
        package: "db"
        out: "./db/sqlc"
        sql_package: "pgx/v5"
        emit_json_tags: true
        overrides:
          - db_type: "numeric"
            go_type: 
              type: "float64"