9Dave9
Hello,
I have a query, where I’d like to grab all records still in the future.
def get_scheduled_notification_pushes_from_date(date\\DateTime.utc_now()) do
query = from s in ScheduledPush,
where: s.status not in ["completed", "cancelled"] and s.utc_schedule_time >= ^date
Repo.all(query)
end
I thought that this would possibly get converted or cast for postgres - but it must be doing something weird.
I also tried comparing ~U[] objects.. but that’s a bad idea…
iex(37)> ~U[2020-08-15 20:39:00.000000Z] >= ~U[2020-08-15 20:36:10.367654Z]
warning: invalid comparison with struct literal ~U"2020-08-15 20:39:00.000000Z". Comparison operators (>, <, >=, <=) perform structural and not semantic comparison. Comparing with a struct literal is unlikely to give a meaningful result. Modules typically define a compare/2 function that can be used for semantic comparison
false
How do I look for records based on a value that is ahead of DateTime.utc_now() with Ecto?
The type for utc_schedule_time is utc_datetime_usec
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
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.
My team and I have been working on a fairly modest app based around video streaming and chat, but we’ve landed a customer t...
New
I really like the adapter patterns that ecto, nebulex, waffle, etc. use and would love find something similar for a key management servic...
New
Hello folks!
So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
I’m working on a small exercise involving update_in/3, and I came up with this solution:
data = %{
name: "Periodic Table",
category:...
New
How Can I Optimise Compile Time Dependencies
I have been building an elixir application for about 2 years now. Many modules and files ha...
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
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
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
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
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
- #ai
- #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 8- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
al2o3cr
This looks like it should work - how does it fail?
The behavior of
>=on~Uis a standard gotcha ->=compares things in Erlang term order, which compares structs field-by-field, alphabetically. Since this is not what you likely want, the compiler emits a warning.9Dave9
Hi,
Yeh so I just realised they’re seen as maps and the keys are what are being compared apparently.|
I swapped the above out with this:
From the docs here
Still get no results and there are results in the DB to pull.
al2o3cr
That other query also looks like it should work.
Does anything unusual show up when you convert it to SQL with
Ecto.Adapters.SQL.to_sql?Double-check that the data that comes back when you do
Repo.all(ScheduledPush)matches what you expect; maybe there’s a errant UTC conversion offsetting things?9Dave9
The schema type for that field is
:utc_datetime_usec.SQL:
[{"SELECT s0.\"id\", s0.\"body\", s0.\"channel_id\", s0.\"timezone\", s0.\"title\", s0.\"user_ids\", s0.\"utc_schedule_time\", s0.\"local_schedule_time\", s0.\"utc_send_time\", s0.\"status\", s0.\"confirmed_send_count\", s0.\"inserted_at\", s0.\"updated_at\" FROM \"scheduled_notification_pushes\" AS s0 WHERE (NOT (s0.\"status\" IN ('completed','cancelled')) AND (s0.\"utc_schedule_time\" < $1::timestamp + interval '1 microsecond'))", [~U[2020-08-16 01:26:47.451151Z]]}I think it’s because it’s still trying to compare with a ~U object.
If I run the plain SQL I get the correct results it seems but this returns my results in a random List format which is insanely difficult to map and work with.
i.e
9Dave9
=======================UPDATE =====================
This works:
This doesn’t
This also doesn’t work
Looks like adding in an
andwith more conditions change the datetime part of the query somehow.I can’t see anything obvious still though.
9Dave9
======================= SOLUTION - PROBLEM SOLVED =====================
The original query I thought was giving me problems was:
Not realizing that Ecto would cast the date types appropriately to play nicely with postgres/SQL I went the terminal and did the
~U[some date] < ~U[some date]- silly and I got the gotcha notification to remind me.I thought this is what was probably happening in the query and I need to cast those values manually.
Turns out if you have
nullvalues in a column and you try and string match - some how this does something weird where it doesn’t evaluate the record maybe? I don’t know.. all I know is that the moment I do try and string match on a field which wasnullto begin with this row is no longer considered even if all the conditions pass.I migrated all the values to “pending” to check this.. and
Voila:
My final though was maybe this might be a
validate_requiredfield in the schema and hence the result from the query being removed - nope, it’s not a require field either.al2o3cr
The problem is the NULL -
NULL IN ('completed', 'canceled')doesn’t evaluate tofalseit evaluates toNULL, andNOT(NULL)is stillNULL.9Dave9
Ah yes, I see. Thanks for the help!