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

adding multiple postgres interval formats #50

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

huehnerhose
Copy link

Since it's a postgres server side configuration which interval primarily is used (postgres, sql, postgres verbose, iso8601) the pg.Interval has to handle multiple "input" formats.

I needed iso8601 support (fast). That PR is more a POC to determine which format the server uses and implementing a POC-style iso8601 parsing, which only supports secods as resolution.

ToDo here would be:

  • verify format detection
  • build a testable format switch (I had to reconfigure and restart postgres)
  • implement postgres verbose and sql standard parsing
  • properly implement iso8601 parsing

@jackc
Copy link
Owner

jackc commented Aug 4, 2020

A few thoughts: If you use the binary format you don't have to worry about interval format. But if you need to work with the text format it would be nice to avoid detecting the format each time. I've considered adding adding the server parameters to ConnInfo. IIRC the server reports IntervalStyle on connection and whenever it is changed. That could make things simpler.

@huehnerhose
Copy link
Author

Thanks for the input, but: What do you mean by using the binary format? For background, I stumbled in this whole topic because of an scanning error with a differently configured server, using an older version von pgx/pgtype (3.something)

If there is a better way omitting the textformat altogether, I am all in!

Detecting the text format by not using regex would be great, too ;)

@jackc
Copy link
Owner

jackc commented Aug 5, 2020

PostgreSQL has two transfer formats for almost all data types: a text format and a binary format. The text format is what you see in psql and what is affected by the various set options (e.g. IntervalStyle). For the interval type the format is microseconds as an int64, days as a int32, and months as a int32. This 16 byte binary format is much simpler and faster to parse than the text format -- and is unaffected by IntervalStyle.

pgx uses the binary format by default, so unless the text format is chosen for some reason it should "just work" without any changes.

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

Successfully merging this pull request may close these issues.

2 participants