sqlc-dev / sqlc

Generate type-safe code from SQL
https://sqlc.dev
MIT License
13.46k stars 805 forks source link

`timestamp` cannot map to `time.Time` and `emit_null_pointer_for_null_types` not work #3709

Open i11010520 opened 3 hours ago

i11010520 commented 3 hours ago

Version

1.27.0

What happened?

I wanna map timestamp with time zone to time.Time or *time.Time when nullable, but it always generates to be pgtype.Timestamptz (even for nullable).

just like d1 and d2 at play.

Relevant log output

No response

Database schema

No response

SQL queries

No response

Configuration

No response

Playground URL

https://play.sqlc.dev/p/932bb09938a263e32515fb123186cf613a9317004d0ac54437e837217a06980c

What operating system are you using?

macOS

What database engines are you using?

PostgreSQL

What type of code are you generating?

Go

i11010520 commented 2 hours ago

I tried to use pg_catalog.timestamptz, it works for NOT NULL field, but the nullable field will generate **time.Time instead of *time.Time (even without emit_pointer_for_null_types).

overrides:
  go:
    overrides:
      - db_type: "pg_catalog.timestamptz"
        go_type: "time.Time"
      - db_type: "pg_catalog.timestamptz"
        nullable: true
        go_type: "*time.Time"

like: https://play.sqlc.dev/p/af8dfab8c2e50b02d6b70cfb20695385b0d96f8a0fcbe300fd82f6a852e4b1a8