Skip to content

Implement scanner for range/array for postgresql types #2454

@Micrococonut

Description

@Micrococonut

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions