tj0
I’m currently trying to store dates in Postgresql that are before ISO8601 ‘year 0’ and am running into issues. Postgresql stores dates internally as JD and can correctly insert/remove dates. I’m storing the date generally as NaiveDateTime and it works fine for anything > year 0.
For instance, the following query works fine in SQL.
sql> insert into table1 set t = '1000-01-01BC 00:00:00';
However, trying to load this in Ecto doesn’t seem to work as we’re referring to a calendar function that doesn’t have any representation of times before 0.
(stdlib 3.13) calendar.erl:257: :calendar.last_day_of_the_month/2
(stdlib 3.13) calendar.erl:133: :calendar.date_to_gregorian_days/3
(stdlib 3.13) calendar.erl:155: :calendar.datetime_to_gregorian_seconds/1
(postgrex 0.15.8) lib/postgrex/extensions/timestamp.ex:48: Postgrex.Extensions.Timestamp.encode_elixir/1
(postgrex 0.15.8) lib/postgrex/type_module.ex:897: Postgrex.DefaultTypes.encode_params/3
(postgrex 0.15.8) lib/postgrex/query.ex:75: DBConnection.Query.Postgrex.Query.encode/3
-spec datetime_to_gregorian_seconds(DateTime) -> Seconds when
DateTime :: datetime(),
Seconds :: non_neg_integer().
datetime_to_gregorian_seconds({Date, Time}) ->
?SECONDS_PER_DAY*date_to_gregorian_days(Date) +
time_to_seconds(Time).
What’s the appropriate way for dealing with this? As far as I know, erlang/elixir doesn’t have any methodology for monkey-patching, the only thing I could think of is to store these dates in an alternative format as a workaround. Any thoughts?
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
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
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
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
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
Other Trending Topics
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
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
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
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #security










Showing Posts 2 to 1- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
tj0
Awesome. I looked through the code and I patched the library in this branch which could serve as a starting point for a PR. It seems to be working (at least for me).
It appears to me only two files needed modification, but I suppose the patch could be bigger to cleanup all instances of :calendar. And I have no idea what Jose is talking about “internal rata die” representation, so I’m just going to use the branch for now and watch and learn.
kip
I think thats a bug in Postgrex (I will open an issue and a PR) since
t:NaiveDateTimesupports negative years I think its reasonable that Postgrex should.As an alternative I would suggest implementing your own Ecto custom type (if you’re using Ecto) so you can do your own encoding.
EDIT: This issue is already on the Postgrex issue tracker