Open Zevgon opened 7 months ago
Yeah that makes sense....I think ideally it'd be handled by postgres-interval
since that's what's doing the parsing there (I assume via pg-types
)...but you're right a custom type parser would also get you by in this situation. I'll think about other things that might help though and get back to ya in some time. Finishing up a contract engagement ATM and am super busy, but should be free soon!
Sounds great thanks for the quick reply!
Our workaround is to cast interval
to text
in the query.
pg
version: 8.11.3How to reproduce:
Create a table with an interval field and add a row:
Run the following statements:
Intervals are returned correctly if you remove the
SET intervalstyle
line.Commentary
IIUC this is because
node-postgres
uses postgres-interval under the hood, andpostgres-interval
doesn't know how to handle ISO 8601 values. This is called out in their docs:You can see this behavior more directly by going to npm playground and running the following snippet:
I'm filing an issue here rather than in
postgres-interval
because it's debatable what the expected behavior should be forpostgres-interval
users, but it's more clear fornode-postgres
users that theintervalstyle
shouldn't affect the return value. Let me know if I'm off base though, and I can file this ticket there insteadWorkarounds
Open to suggestions. In my team's case, we can't just remove the
SET intervalstyle
statement, since we run that statement it in the pool's on-connect listener, and we want iso_8601 for all our queries. The only option I can think of would be to create a custom type parser: