Relax restriction on allowed year for Date
linusdm opened this issue · 1 comments
linusdm commented
Elixir version
1.17.0
Database and Version
PostgreSQL 15.0
Postgrex Version
0.18.0
Current behavior
{:ok, pid} = Postgrex.start_link(hostname: "localhost", username: "postgres", password: "postgres")
Postgrex.query!(pid, "SELECT $1::DATE", [Date.new!(9_999, 12, 31)])
Postgrex.query!(pid, "SELECT $1::DATE", [Date.new!(10_000, 1, 1)])
The last query results in
** (ArgumentError) Date.new!(10000, 1, 1) is beyond the maximum year 9999
(postgrex 0.18.0) lib/postgrex/extensions/date.ex:41: Postgrex.Extensions.Date.encode_elixir/1
(postgrex 0.18.0) lib/postgrex/type_module.ex:947: Postgrex.DefaultTypes.encode_params/3
Expected behavior
Elixir 1.17 allows a Date to be outside the -9999..9999 range.
Postgrex seems to have this maximum year (not a minimum…) hard-coded when dealing with Dates.
Should the handling of Dates be changed to be in accordance with the new way of handling years in Elixir 1.17? Or are there other constraints in play here that are imposed by Postgres?
greg-rychlewski commented
I think we need to remove it from timestamptz as well. That one looks like a more involved change though.