{"action":"created","issue":{"url":"https://api.github.com/repos/elixir-ecto/postgrex/issues/417","repository_url":"https://api.github.com/repos/elixir-ecto/postgrex","labels_url":"https://api.github.com/repos/elixir-ecto/postgrex/issues/417/labels{/name}","comments_url":"https://api.github.com/repos/elixir-ecto/postgrex/issues/417/comments","events_url":"https://api.github.com/repos/elixir-ecto/postgrex/issues/417/events","html_url":"https://github.com/elixir-ecto/postgrex/issues/417","id":370353867,"node_id":"MDU6SXNzdWUzNzAzNTM4Njc=","number":417,"title":"Postgrex expected %NaiveDateTime{}","user":{"login":"benwilson512","id":247817,"node_id":"MDQ6VXNlcjI0NzgxNw==","avatar_url":"https://avatars1.githubusercontent.com/u/247817?v=4","gravatar_id":"","url":"https://api.github.com/users/benwilson512","html_url":"https://github.com/benwilson512","followers_url":"https://api.github.com/users/benwilson512/followers","following_url":"https://api.github.com/users/benwilson512/following{/other_user}","gists_url":"https://api.github.com/users/benwilson512/gists{/gist_id}","starred_url":"https://api.github.com/users/benwilson512/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benwilson512/subscriptions","organizations_url":"https://api.github.com/users/benwilson512/orgs","repos_url":"https://api.github.com/users/benwilson512/repos","events_url":"https://api.github.com/users/benwilson512/events{/privacy}","received_events_url":"https://api.github.com/users/benwilson512/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":7,"created_at":"2018-10-15T21:36:58Z","updated_at":"2018-10-15T23:08:00Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"Hey folks. Under Postgrex 0.13 and Ecto 2.2.10 the following works:\r\n\r\n```elixir\r\niex(3)> now = DateTime.utc_now                                                               \r\n#DateTime<2018-10-15 21:28:04.061218Z>\r\niex(4)> Repo.all from u in Sensetra.Model.User, where: fragment(\"? >= ?\", u.updated_at, ^now)\r\n[]\r\n```\r\n\r\nNow under 0.14 and Ecto 3.0.0-rc.0, it works when using the column:\r\n```elixir\r\niex(3)> now = DateTime.utc_now                                             \r\n#DateTime<2018-10-15 21:24:24.886315Z>\r\niex(4)> Repo.all from u in Sensetra.Model.User, where: u.updated_at >= ^now\r\n[]\r\n```\r\n\r\nBut no longer when using a fragment:\r\n```elixir\r\niex(5)> Repo.all from u in Sensetra.Model.User, where: fragment(\"? >= ?\", u.updated_at, ^now)\r\n** (DBConnection.EncodeError) Postgrex expected %NaiveDateTime{}, got #DateTime<2018-10-15 21:24:24.886315Z>. Please make sure the value you are passing matches the definition in your table or in your query or convert the value accordingly.\r\n    (sensetra) /Users/ben/src/sensetra/deps/postgrex/lib/postgrex/type_module.ex:713: Sensetra.PostgresTypes.encode_params/3\r\n    (postgrex) lib/postgrex/query.ex:62: DBConnection.Query.Postgrex.Query.encode/3\r\n    (db_connection) lib/db_connection.ex:1074: DBConnection.encode/5\r\n    (db_connection) lib/db_connection.ex:1172: DBConnection.run_prepare_execute/5\r\n    (db_connection) lib/db_connection.ex:1268: DBConnection.run/6\r\n    (db_connection) lib/db_connection.ex:480: DBConnection.parsed_prepare_execute/5\r\n    (db_connection) lib/db_connection.ex:473: DBConnection.prepare_execute/4\r\n    (ecto_sql) lib/ecto/adapters/sql.ex:531: Ecto.Adapters.SQL.execute!/4\r\n```\r\n\r\nThe column type in the database is `timestamp without time zone` and in the ecto schema it's `:utc_datetime_usec`.\r\n\r\nLooking at the postgrex code it seems like it's expecting the database types `timestamp` vs `timestampz` 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-postgresql\r\n\r\nBy specifying the `:utc_datetime_usec` schema type I'm stipulating that the column stores UTC datetimes, so it ought to accept Elixir `DateTime`."},"comment":{"url":"https://api.github.com/repos/elixir-ecto/postgrex/issues/comments/430044594","html_url":"https://github.com/elixir-ecto/postgrex/issues/417#issuecomment-430044594","issue_url":"https://api.github.com/repos/elixir-ecto/postgrex/issues/417","id":430044594,"node_id":"MDEyOklzc3VlQ29tbWVudDQzMDA0NDU5NA==","user":{"login":"benwilson512","id":247817,"node_id":"MDQ6VXNlcjI0NzgxNw==","avatar_url":"https://avatars1.githubusercontent.com/u/247817?v=4","gravatar_id":"","url":"https://api.github.com/users/benwilson512","html_url":"https://github.com/benwilson512","followers_url":"https://api.github.com/users/benwilson512/followers","following_url":"https://api.github.com/users/benwilson512/following{/other_user}","gists_url":"https://api.github.com/users/benwilson512/gists{/gist_id}","starred_url":"https://api.github.com/users/benwilson512/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benwilson512/subscriptions","organizations_url":"https://api.github.com/users/benwilson512/orgs","repos_url":"https://api.github.com/users/benwilson512/repos","events_url":"https://api.github.com/users/benwilson512/events{/privacy}","received_events_url":"https://api.github.com/users/benwilson512/received_events","type":"User","site_admin":false},"created_at":"2018-10-15T23:08:00Z","updated_at":"2018-10-15T23:08:00Z","author_association":"CONTRIBUTOR","body":"Side note: In re-reading my posts I sound sort of annoyed, sorry about that, Ecto 3.0 looks like a ton of work and I really appreciate what everyone has done.\r\n\r\nDowncasting would be really nice, particularly in this case where all the ordinary Ecto functions seem to already be doing that happily."}}
{"actor":{"display_login":"benwilson512"}}