Timestamp formatted differently if fetched as relation rather than directly
Hi team,
I'm using
"drizzle-orm": "^0.30.7"
with a PostgreSQL DB and postgres-js etc.
I'm seeing a little issue that I can't get to the bottom of, whereby timestamps are being formatted differently on retrieval from the DB, depending on whether the entity is being queried directly, or whether it is included via a relation on another entity when that is queried.
Querying directly, the timestamps are in a readable but non-ISO format:
As a relation, the same timestamps are in the desired ISO format:
The schema for these two timestamp fields looks like this
Ideally everything would be returned in the ISO format, so that we can handle these consistently when displaying in the rest of our application.
Any ideas if I'm missing something?
Thank you!11 Replies
@Aaroned have you come across something like this before? Or know who may be the person to ask?
@Dan Kochetov @alexblokh are you able to help with the issue above please?
Yep, that’s a bug
cc: @Dan Kochetov
what do you mean "queried directly"? could you provide your queries in code?
Thanks that's good to know. Do you have a triage process/a rough idea when we could expect a fix for it?
Sure, the entity in question here is a "Farm", which also has a 1 to many relationship with an "Assessment". We can either fetch this from the "farm" table as a standalone object (in which the timestamp appears to be formatted incorrectly), or we can fetch an "Assessment" from the "assessment" table "with" its corresponding "Farm" (in which case the timestamp is formatted correctly).
could you provide your schema w/ relations and the query samples?
Query for standalone farm:
Query for assessment with farm:
Farms schema:
Assessment schema:
@Dan Kochetov I've put
...
to hide fields which shouldn't be relevant. Hopefully that's enough for you to go on?thank you
could you also create an issue on GitHub and link it to this thread?
just to keep track
Cool - have created an issue here - https://github.com/drizzle-team/drizzle-orm/issues/2282. I've just linked to this thread atm, but I can copy in the detail if that's helpful?
GitHub
Issues · drizzle-team/drizzle-orm
Headless TypeScript ORM with a head. Runs on Node, Bun and Deno. Lives on the Edge and yes, it's a JavaScript ORM too 😅 - Issues · drizzle-team/drizzle-orm
yes, please copy it
Done, I appreciate the support 🙂
found the problem and updated the linked issue, fyi
tl;dr is that the relational query system casts the rows to json, and postgres to_json on a timestamp converts it to ISO, where a plain select returns it in sql timestamp format