Implement scanner for range/array for postgresql types
- Dominant language
- Go
- Stars
- 14.3k
- Forks
- 1.1k
- Avg merge
- 6d 9h
- Merged PRs (30d)
- 11
Description
I was migrating my project to v5 today and I hit a roadblock. I was trying to move from Tstzrange to the Range[Timestamptz] generic interface but my tests were failing with:
> name "systime": unsupported Scan, storing driver.Value type string into type *pgtype.Range[github.com/jackc/pgx/v5/pgtype.Timestamptz]
for my struct
`type TelemetryMapHistory struct {
HistoryID uint 'gorm:"primarykey"'
Systime pgtype.Range[pgtype.Timestamptz] 'gorm:"not null; type:tstzrange"'
...
}`
So I did some digging and found that the Range type does not implement the scan interface.
so I made my own type and implemented it myself and it works.
`type Tstzrange pgtype.Range[pgtype.Timestamptz]`
It seems as though this has been asked for in the past (#2421) but was denied due to upcoming golang changes (#2403) which are now no longer happening. Am I doing something wrong here? Is it expected that any users who want to use range types have to implement these functions themselves?
Contributor guide
Research direction
Start with pgtype.Range[pgtype.Timestamptz] and the failing database/sql Scan path described in the issue. Compare the range and array types involved, then verify that a struct field using Range[Timestamptz] can scan a PostgreSQL tstzrange value without a user-defined alias or scanner implementation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, postgresql
- Domain
- databases
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100