Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PostgreSQL like Range/Multirange Functions #2253

Open
munnik opened this issue Feb 10, 2025 · 2 comments
Open

Add PostgreSQL like Range/Multirange Functions #2253

munnik opened this issue Feb 10, 2025 · 2 comments

Comments

@munnik
Copy link

munnik commented Feb 10, 2025

Is your feature request related to a problem? Please describe.
pgx defines a Range[T] type that can be used to store PostgreSQL ranges. I use the ranges in a CopyFrom call, but sometimes the call contains one or more overlapping ranges that are not allowed in my table definition. Therefore, the whole CopyFrom fails. It would be helpful if I could use the functions/operators as defined in https://www.postgresql.org/docs/current/functions-range.html to check the records I have before insert. I could imagine that for other use cases other functions/operators are helpful if they can be applied already in Go.

Describe the solution you'd like
I would like to add these functions in a file range_functions.go and range_functions_test.go in the pgtype package. Would you include these in pgx (pull request) or is it better to make a separate project for these functions?

Describe alternatives you've considered
A separate project that uses pgtype.Range[T].

@jackc
Copy link
Owner

jackc commented Feb 17, 2025

I think this would make sense as a separate project at least to start. It might even make sense to have these types be independent of pgtype.Range[T]. Range types and functionality would be useful in Go independent of PostgreSQL. They could be modeled off of the PostgreSQL system. And an adapter could be made that implements RangeValuer and RangeScanner. This would let the projects integrate without direct dependencies. For example, it would be like the shopspring/decimal package is used with pgx.

@munnik
Copy link
Author

munnik commented Feb 24, 2025

Thanks,

I was already working on it, see https://github.com/munnik/pgx_range_operator. Not yet a stable interface, so comments are more than welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants