Open xakepp35 opened 2 months ago
Here are some things you could try in rough order of difficulty:
SELECT created_at::text FROM table
).QueryExecModeExec
.string
backed type that implements Timestamp(tz)Scanner
. Cast your string to it when you scan. See the zeronull
package for an example of that style.Timestamp(tz)Codec
from pgx into your project, change it to allow scanning to a string
, and register your new Codec
on the connection.TryWrapScanPlanFunc
that implements your custom behavior.Just ran into it, and somehow got it working.
type SomeObject struct {
OID pgtype.Int8 `json:"oid"`
}
Now SomeObject.OID.Int64
does give desired OID. @jackc what you think of it?
@hmoazzem I don't see how that code relates to scanning a binary timestamp
into a *string
.
Maybe after looking at several issues I lost track of relevance. I was getting error scanning OID field, so searched and looked at many issues with OID in title
Anyway, what go data type would you (recommend to) use for OID?
@hmoazzem uint32
or https://pkg.go.dev/github.com/jackc/pgx/v5@v5.7.1/pgtype#Uint32 if you need it to be nullable.
Describe the bug I am using protobuf generated structures, and it does not have time.Time type. However it have string type, which is sufficient for my goals. But library does not allow to scan timestamp as string. How can i do so? I cannot modify Response struct, as its a generated code. Also i dont want to copy from intermediate struct.
To Reproduce try to scan timestamp column to *string field
Expected behavior CreatedAt containing timestamp in RFC3339Nano string format
Actual behavior non-nil err, containing message: "cannot scan timestamp (OID 1114) in binary format into *string"