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
Postgrex expected %NaiveDateTime{} #417
Comments
The underlining reason this crashes is we always send timestamps as where: fragment("? >= ?", u.updated_at, type(^now, :utc_datetime_usec)) I actually run into a similar issue recently, but I don't yet know if we can improve it. |
Hey @wojtekmach. I suppose what I'm unclear on is how it figures out that it's a timestamp column but not that it's a What approach was used in Postgrex 0.13? |
The error comes not from the
when I was testing this I think I saw it sent as |
If it has that mapping then that seems like an error. It's also inconsistent with how the rest of Ecto / Postgrex handles that column both now and historically. If your ecto schema specifies |
Right, but I think in order to return timestamp in client timezone the only option is to put it into %DateTime{}. In practice we only allow UTC anyway [1] but I assume the idea was to eventually support different client’s timezones. Btw Im not arguing against what you’re saying, just showing my understanding (which might be wrong!) [1] https://github.com/elixir-ecto/postgrex/blob/v0.14.0-rc.1/lib/postgrex/extensions/timestamptz.ex#L41 |
@wojtekmach that makes sense, I definitely get why values that come from a I guess what I'm not clear on right now is whether the 0.14 behaviour is considered a bug / problem, or whether the aim is for this to intentionally be the new normal. |
Right, timestampz does not include the timezone but we allegedly know the timezone based on the connection (and postgrex requires it to always be UTC). We could however allow datetimes in timestamp (without zone), because downcasts are usually ok. |
Side note: In re-reading my posts I sound sort of annoyed, so I apologize for that. Ecto 3.0 and Postgrex 0.14 looks like a ton of work and I sincerely appreciate what everyone has done. Downcasting would be really nice, particularly in this case where all the ordinary Ecto functions seem to already be doing that happily. |
I have talked to @ericmj and we agreed on downcasting Datetime to NaiveDatetime (ignoring the offset fields, which is what Elixir does) for timestamp without zone exclusively. This should be relatively straight-forward to implement and if anyone wants to submit a PR it is very appreciated. 👍 |
Hey folks. Under Postgrex 0.13 and Ecto 2.2.10 the following works:
Now under 0.14 and Ecto 3.0.0-rc.0, it works when using the column:
But no longer when using a fragment:
The column type in the database is
timestamp without time zone
and in the ecto schema it's:utc_datetime_usec
.Looking at the postgrex code it seems like it's expecting the database types
timestamp
vstimestampz
to match up with NaiveDateTime vs DateTime but that would be a mistake. Neither column type stores timezone information, it's entirely about whether the values are returned in the client local timezone or not: https://stackoverflow.com/questions/5876218/difference-between-timestamps-with-without-time-zone-in-postgresqlBy specifying the
:utc_datetime_usec
schema type I'm stipulating that the column stores UTC datetimes, so it ought to accept ElixirDateTime
.The text was updated successfully, but these errors were encountered: