e94
Hi,
I’m new to Elixir. So sorry if I missed something.
I cannot make this query work:
alias Uniq.UUID
mandate_uuid = "6bf40047-117d-4056-b964-e54545f901ac"
mandate_uuid = UUID.string_to_binary!(mandate_uuid)
Repo.delete_all(
from(bp in BalancePoint,
where:
bp.date >= ^start_time and bp.date <= ^end_time and
bp.mandate_uuid == type(^mandate_uuid, :binary_id)
)
)
I ve got the following error:
value `<<107, 244, 0, 71, 17, 125, 64, 86, 185, 100, 229, 69, 69, 249, 1, 172>>`
cannot be dumped to type :binary_id in query
Here is my schema:
@primary_key false
@foreign_key_type :binary_id
schema "balances_points" do
field(:uuid, :binary_id, primary_key: true)
field(:date, :utc_datetime)
field(:asset, :string)
field(:mandate_uuid, :binary_id)
field(:total_quantity, :decimal)
timestamps()
end
The following code works with Postgrex :
alias Uniq.UUID
mandate_uuid = "6bf40047-117d-4056-b964-e54545f901ac"
mandate_uuid = UUID.string_to_binary!(mandate_uuid)
query = """
DELETE FROM balances_points
WHERE
date >= $2::timestamp
and date <= $3::timestamp
and mandate_uuid = $1;
"""
Ecto.Adapters.SQL.query(Repo, query, [mandate_uuid, start_time, end_time])
I don’t understand what’s wrong with Repo.delete_all.
Thks
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
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
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
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
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
Other Trending Topics
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
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
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
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
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming











Showing Posts 1 to 8- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
benwilson512
Hi @e94 I don’t think you need to manually cast anything, you should be able to do:
e94
Hi @benwilson512
Thanks for your reply.
I’ve tried also.
It gives the following error:
codeanpeace
I’d take a look at the Ecto.UUID module that comes with Ecto. In particular, it might be worth trying Ecto.UUID.cast!/1 and Ecto.UUID.dump!/1.
Off the top of my head, a possible reason the same approach is not working for the first query, but is fine for the second query is because the second query uses string interpolation.
Also, is there a particular reason why you’re using
Uniq.UUID? I’d suggest seeing ifEcto.UUIDcan replaceUniq.UUIDfor your use case, especially since you’re already using Ecto to interface with Postgres. For reference, check out this article on https://pawelurbanek.com/elixir-phoenix-uuid.e94
Hi @codeanpeace
Thanks for your help.
I’ve tried also with Ecto cast and dump.
It leads to the same errors.
I’m using Uniq because it supports UUIDv6 and v7, which are more convenient than v4. I don’t think Ecto supports v6 and v7.
joey_the_snake
Would you be able to post a small reproducible repo? What Ben said should work.
e94
Hi @joey_the_snake,
Thanks for the suggestion.
I’ve done it. And it works as mentionned by @benwilson512.
So I need to find what’s wrong in the other project.
e94
My bad. The error was raised a few lines after the call to
Repo.delete_all…Thanks @benwilson512 @codeanpeace @joey_the_snake for your help.
joey_the_snake
If you’d like some more info about the process Ecto uses: