In many cases it’s useful to tell
sqlc explicitly what Go type you want it to
use for a query input or output. For instance, a PostgreSQL UUID type will map
github.com/jackc/pgx/pgtype by default when you use
pgx/v5, but you may want
sqlc to use
If you’d like
sqlc to use a different Go type, specify the package import
path and type in the
version: "2" sql: - schema: "postgresql/schema.sql" queries: "postgresql/query.sql" engine: "postgresql" gen: go: package: "authors" out: "db" sql_package: "pgx/v5" overrides: - db_type: "uuid" go_type: import: "github.com/google/uuid" type: "UUID"
Each element in the
overrides list has the following keys:
A column name to override. The value should be of the form
table.columnbut you can also specify
db_typeare mutually exclusive.
The fully-qualified name of a Go type to use in generated code. This is usually a string but can also be a map for more complex configurations.
A reflect-style struct tag to use in generated code, e.g.
a:"b" x:"y,z". If you want
dbtags for all fields, use
true, sqlc will apply this override when a column is nullable. Otherwise
sqlcwill apply this override when a column is non-nullable. Note that this has no effect on
columnoverrides. Defaults to
Note that a single
db_type override configuration applies to either nullable or non-nullable
columns, but not both. If you want the same Go type to override in both cases, you’ll
need to configure two overrides.
When generating code, entries using the
column key will always take precedence over
entries using the
Some overrides may require more detailed configuration. If necessary,
can be a map with the following keys:
The import path for the package where the type is defined.
The package name where the type is defined. This should only be necessary when your import path doesn’t end with the desired package name.
The type name itself, without any package prefix.
true, generated code will use a pointer to the type rather than the type itself.
true, generated code will use a slice of the type rather than the type itself.
version: "2" sql: - schema: "postgresql/schema.sql" queries: "postgresql/query.sql" engine: "postgresql" gen: go: package: "authors" out: "db" sql_package: "pgx/v5" overrides: - db_type: "uuid" go_type: import: "a/b/v2" package: "b" type: "MyType" pointer: true