ourway
Trending in Discussions
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
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
Hi there! :wave:
@frigidcode and I (but mostly him) have been running an Elixir Book club, we’re almost done with Designing Elixir Syste...
New
I’ve been using Emacs as my main code editor for more than a two years. It’s a custom build version although I’ve tried doom emacs and sp...
New
I love Elixir. It’s one of 2 programming languages I’ve ever fallen in love with.
But I don’t use it anymore.
Serverless was the promis...
New
Lately I’ve been thinking about how to organize components as a LiveView application grows. One of the pain points I’ve found (for myself...
New
What IDE or editor are you using for Elixir development?
Personally, I use Zed, and I really like it, but sometimes I wish there were a ...
New
Other Trending Topics
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
In 2021 I started a new library called Tempo with the objective of modelling time as a set of intervals - not as instants. In 2022 I gave...
New
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly)
AI dream has many faces, but general...
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
- #ai
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
Exadra37
I am curious about things you think that Ecto is doing from that list?
LostKobrakai
At least
4.1, but there are valid reasons to not follow the advice.NaiveDateTimealready doesn’t involve timezones andDateTimeis enforced to have UTC set as timezone at the time of insertion (runtime). Sotimestampis the better default overtimestamptzbecause you can be sure the database won’t ever try to convert the timestamp. Basically ecto is already doing whattimestamptzis supposed to do overtimestampbut it does so in it’s own control.Also I’d imagine the ecto team is well aware of what they’re doing.
See this for a response on the above: utc_datetime having no affect on PostgreSQL DDL · Issue #1868 · elixir-ecto/ecto · GitHub
jdumont
The “don’t use table inheritance…never…use foreign keys instead” is relevant to a discussion I was having last week. That said, we came to the foreign key conclusion, and table inheritance isn’t suggested by the Ecto docs anyway.
I think Ecto keeps to those rules and hides away a lot of the potential pitfalls on that list (
moneytype, uppercase column names, etc.)hubertlepicki
Ecto is doing it because over binary protocol that postgrex uses, timestamp and timestamptz is precisely the same thing.
Most postgresql connectors use text based protocol, in other languages. Postgrex uses binary protocol. It doesn’t understand client’s time zone.
I do think that, however, timestamptz is a safer choice, especially when other clients can connect to database. For example, if you ever connect using
psql, you could see dates & times in different time zone because of your client configuration and then this can even lead to mistakes. I guess it’s OK if you are aware of the issue. But for the consistency and possible error avoidance, I like to uze timestamptz everywhere which forces the dates to be displayed in UTC no matter what your client is.I have written about it more in details here: Time zones in PostgreSQL, Elixir and Phoenix | AmberBit Sp. z o. o.
peerreynders
http://www.postgresqltutorial.com/postgresql-timestamp/:
So the database server establishes the context for your time data?
So recording all time data as UTC (for ease of point in time comparison without interference of DST) and recording the event timezone separately makes universally more sense (there are always exceptions).
Accepting the database server timezone as the centre of the universe seems myopic.
I think the real issue is that clients assume that time without a timezone reflects their own timezone. The ambiguity is gone if you establish upfront that any time without a timezone is always UTC (however inconvenient that may be).
A phone call today between São Paulo and Warsaw could have started at 14:00 UTC but would have been observed by the parties involved at 11:00 (-03:00) and 16:00 (+02:00 (DST)) respectively.
To be clear:
timestamptzseems to want to do the right thing, i.e. store UTC times.However the type
timestamptzseems to signal that the DB server/driver boundary is the right place to do the conversion. I’m not convinced that in increasingly distributed systems that is necessarily the right place to do it.hauleth
The most important thing on this list that is not possible in Ecto right now is usage of existential queries. Right now the only option is to use anti-joins instead.
sribe
As you point out, that would be terribly inconvenient. However, that description is misleading for two reasons:
The timezone of the database server is merely a default for the timezone of the connection, which you can set to anything you want.
For my local time zone it doesn’t convert
2019-05-10 07:30:00to2019-05-10 00:30:00, but rather2019-05-10 00:30:00-07. So, convenient in the default case, but trivial to parse accurately as UTC and display any way you want… (That’s for text-based protocol, I don’t know the details of binary, but I’d bet that you get UTC without being offset, because it makes no sense to adjust an 8-byte integer for easier reading by humans.)Likewise for sending timestamps to the server, the “assume it’s server/connection time zone” only applies to timestamps which do not specify an offset.
You are right that would be a lousy way to do it, but it’s not really what PG does. Since the offset gets added, it’s not a conversion of the underlying value at all, but rather a guess at a convenient display format.
(Also “timezone of the server” can be specified in the PG config, and it’s common practice in distributed system to set it to UTC, rather than letting the system try to infer the actual time zone.)
OvermindDL1
Yeah I’ve had to help someone who had a
nilin ablah not in ^thing, Ecto really needs to not useNOT INin sql…peerreynders
Probably reflecting some of my confusion at the time (hence my addendum to the post) but I’m still unconvinced that
timestamptzis the cure all that the wiki promotes it to be.It feels like a technological quick fix for a conceptual misunderstanding.
With
timestamp without time zonethe timezone is portrayed as missing which is entirely true when looking at the type and perhaps even the record in which a value of that type exists. But in truth the timezone is usually implied. The problem is that from an individual point of view it is local time that is perceived and recorded. And in legacy systems that often was the frame of reference.However from a global point of view you either need an explicit timezone as a frame of reference or you need a fixed frame of reference, i.e. UTC.
So frankly any time represented/stored without a timezone should be UTC in order to avoid confusion. So storing UTC is the part that
timestamptzgets right.So the good news is that the UTC value is sent to the querying system. The bad news is that the value displayed in the an admin tool like
psqlwon’t match it unless youset timezone to 'UTC';- I can see that generating a lot of confusion.I’m assuming that
2019-05-10 07:30:00refers to the already stored value, because:i.e. a string without a timezone, parsed inside the server is going to assume the set timezone or
timezonefrom thepostgresql.conf. Butguards against that.
Seems don’t put anything but UTC into
timestampis a simpler solution to the problem (which seems to be the Ecto approach - and the “convenience” oftimestamptzisn’t needed anyway).Another problem that
timestamptzdoesn’t fix - ambiguity during local end of daylight savings (unless server/connection is set to UTC or ignore DS).yurko
There’s also 5.1:
Ecto does it as far as I can tell, setting
:stringtype without specifying size would produce varchar that is limited with 255 characters and it will indeed throw a database level error on an attempt to insert a longer value. I’ve got this error once or twice in the past and had to go back and explicitly validate / cast each string value.This is probably because Ecto must support other databases including older versions of MySQL but still legit point with mentioned consequences.