cannot scan timestamp (OID 1114) in binary format into *string
- Dominant language
- Go
- Stars
- 14.3k
- Forks
- 1.1k
- Avg merge
- 6d 9h
- Merged PRs (30d)
- 11
Description
**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
```go
package main
import (
"context"
"log"
"os"
"github.com/jackc/pgx/v5"
)
type Response struct {
CreatedAt string `protobuf:"bytes,11,opt,name=created_at,json=createdAt,proto3" json:"created_at,omitempty"` // created_at date,
}
func main() {
conn, err := pgx.Connect(context.Background(), os.Getenv("DATABASE_URL"))
if err != nil {
log.Fatal(err)
}
defer conn.Close(context.Background())
var res Response
err := conn.QueryRow(context.Background(), "SELECT created_at FROM table").Scan(&res.CreatedAt)
if err != nil {
panic(err.Error()) // <-- err will follow caption
}
}
```
**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"
Contributor guide
Research direction
Start at the QueryRow(...).Scan entry point and trace handling for PostgreSQL timestamp OID 1114 in binary format. Verify what is needed for a protobuf-generated string field to receive the timestamp in RFC3339Nano format without an intermediate struct.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, postgresql
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100