vlad.grb
Trying to wrap existing Date to support infinity special value
Ecto: 2.2.9
Implemented this
defmodule Utils.Ecto.Types.Date do
@behaviour Ecto.Type
@doc false
def type, do: :date
@doc false
def cast("infinity"), do: {:ok, :"infinity"}
def cast("-infinity"), do: {:ok, :"-infinity"}
def cast(value), do: Ecto.Type.cast(:date, value)
@doc false
def load("infinity"), do: {:ok, :infinity}
def load("-infinity"), do: {:ok, :"-infinity"}
def load(value), do: Ecto.Type.load(:date, value, nil)
@doc false
def dump(:infinity), do: {:ok, "infinity"}
def dump(:"-infinity"), do: {:ok, "-infinity"}
def dump(value), do: Ecto.Type.dump(:date, value, nil)
end
When trying to insert a record getting
1) test support infinite values (FooBar.Hello)
test/foo_bar/hello_test.exs:63
** (CaseClauseError) no case clause matching: {"-infinity"}
stacktrace:
(foo_bar) lib/ecto/types/date.ex:715: FooBar.PostgresTypes.encode_params/3
(postgrex) lib/postgrex/query.ex:45: DBConnection.Query.Postgrex.Query.encode/3
(db_connection) lib/db_connection.ex:1079: DBConnection.describe_run/5
(db_connection) lib/db_connection.ex:1150: anonymous fn/4 in DBConnection.run_meter/5
(db_connection) lib/db_connection.ex:592: DBConnection.prepare_execute/4
(ecto) lib/ecto/adapters/postgres/connection.ex:86: Ecto.Adapters.Postgres.Connection.execute/4
(ecto) lib/ecto/adapters/sql.ex:256: Ecto.Adapters.SQL.sql_call/6
(ecto) lib/ecto/adapters/sql.ex:542: Ecto.Adapters.SQL.struct/8
(ecto) lib/ecto/repo/schema.ex:547: Ecto.Repo.Schema.apply/4
(ecto) lib/ecto/repo/schema.ex:213: anonymous fn/14 in Ecto.Repo.Schema.do_insert/4
(ecto) lib/ecto/association.ex:556: Ecto.Association.Has.on_repo_change/4
(ecto) lib/ecto/association.ex:338: anonymous fn/7 in Ecto.Association.on_repo_change/6
(elixir) lib/enum.ex:1899: Enum."-reduce/3-lists^foldl/2-0-"/3
(ecto) lib/ecto/association.ex:335: Ecto.Association.on_repo_change/6
(elixir) lib/enum.ex:1899: Enum."-reduce/3-lists^foldl/2-0-"/3
(ecto) lib/ecto/association.ex:301: Ecto.Association.on_repo_change/3
(ecto) lib/ecto/repo/schema.ex:708: Ecto.Repo.Schema.process_children/4
(ecto) lib/ecto/repo/schema.ex:774: anonymous fn/3 in Ecto.Repo.Schema.wrap_in_transaction/6
(db_connection) lib/db_connection.ex:1374: DBConnection.transaction_nested/2
(db_connection) lib/db_connection.ex:1234: DBConnection.transaction_meter/3
Tried to read the source but it is too much metacode inside which I can’t understand.
Trending in Questions
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
Hello,
I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind.
However, when I launch mix phx.server, I get an error...
New
Hi everyone,
I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding.
I sta...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
Latest Phoenix Threads
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ai
- #ecto-query
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #metaprogramming
- #hex










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
1player
Looks like postgrex isn’t able to encode an
"infinity"date string, though I might be mistaken. I don’t see any mention of it in postgrex/lib/postgrex/extensions/date.ex at master · elixir-ecto/postgrex · GitHubBut there seems to be some confusion with your usage of atoms and strings.
"infinity"is not equal to:"infinity", and your code seems to use atoms or strings interchangeably.EDIT: Nope, postgrex doesn’t support infinity dates at the moment: postgrex can't handle all possible postgres date/timestamp/timestamptz values · Issue #274 · elixir-ecto/postgrex · GitHub
vlad.grb
This is very bad
vlad.grb
I tried to add missing match for extension
On insert I put dummy values to check what is the output from db.
Then
And then
But
And the doc says that the max date is
5874897 ADQqwy
I do wonder: What is your intended use for this?
vlad.grb
Hmm. Unbounded dates?
For example:
mgwidmann
If I’m not mistaken, this won’t work as the database DATE type cannot be stored as the string
"infinity". The column would have to be a varchar and then you would have to perform date parsing in the where clause (and indexing by it would be poor as well). The best thing I can recommend is when the date is exactly equal to the highest and lowest values in the datetime, those are markers for infinity and negative infinity (looks like 4713 BC and 294276 AD for postgres). Try making your custom type use those values instead.stefanluptak
What about using
NULLfor the purpose ofinfinity? Wouldn’t that be a solution? Then using something likeSELECT * FROM xxx WHERE dateRange @> someDate OR someDate IS NULL;.jwarlander
I can’t speak for your particular domain of course, but in my world I generally tend to use
9999-12-31as the “infinity” date.. I imagine if I had to decide on “-infinity”, I’d go for0001-01-01.Though that’s with the reservation that I generally just have to deal with event timestamps over the lifetime of the company where I work.
Thus.. you could potentially have your extension translate
:infinityto9999-12-31, etc.vlad.grb
NULLis not less or greater than now() it just gives you nothing. So it won’t work.benwilson512
@vlad.grb This is why he uses
OR someDate IS NULL