saialluru
Not sufficient documentation on using Postgres range types
Using raw SQL insert and update into range types does not work
updateSql = “UPDATE " <> type.namespace <> “_” <> type.predicate <> " SET
validity = int4range(lower(validity)::integer, $1::integer, ‘[)’)
where subject = $2 and validity @> $3::integer”
insetSql = "insert into range_table values ($1, '[$2::integer,)'::int4range, $3);"
Repo.transaction fn ->
SQL.query(Repo, updateSql, [intvalue, string value, intvalue])
SQL.query(Repo, insetSql, [stringvalue, intvalue, stringvalue], [])
end
The output does not clearly say what the error is
iex(23)> Postgres.store_sentence(sainame)
[debug] QUERY OK db=0.2ms idle=1404.9ms
begin
[debug] QUERY ERROR db=0.0ms
insert into default_name values ($1, ‘[$2::integer,)’::int4range, $3); [“Sai”, 0, “Alluru”]
[debug] QUERY OK db=0.2ms
rollback
Trending in Announcing
You may know https://ui.shadcn.com/, a UI component library for React. I really love it’s design style and components. I’ve built some co...
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
The Chelekom project is a library of Phoenix and LiveView components generated via Mix tasks to fit developer needs seamlessly.
One of i...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
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
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
Introducing AshStorage! Attachment and file management that slots directly into your resources :smiling_face_with_sunglasses:
I had hope...
New
Other Trending Topics
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
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
We want to introduce a new native datatype to Erlang: native records. Although replacing all tuple records with native records is not our...
New
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
Introduction
Founded in 2017 by landscape ecologist and fire mitigation expert Harry Statter, Frontline developed the first fully integra...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #performance
- #security










First Post!
ruslandoga
Can you post the query you want to execute here? From what I see, you have a typo in the range definition,
[$2::integer,)::int4range:[$2::integer,)is not a valid range.Off-topic, I’d suggest not using raw sql in
Repo.query, and instead going withRepo.insert_all. What you are trying to do can be done withinsert_allin a safer and more idiomatic way.Most Liked
ruslandoga
Note that you posted
[$2::integer,)::int4rangein OP,[$2::integer,)is not a valid range.In
insert_allyou can use Postgrex.Range — Postgrex v0.22.2.Your raw SQL would be roughly equivalent to
ruslandoga
Check the response from
Repo.query, it would contain the error reason. The logs you posted only show the executed queries, how long it took, and their status, they don’t show responses as it would be noisy.ruslandoga
You can probably use a join if the data to be updated is stored in some table:
or if you don’t have a table like that and all your data comes from the app, you might be able to use with_cte/2 in which you’d define the records to be updated and then in the main body you’d run a query similar to the one above:
There are other approaches as well, but that’s not Ecto specific, to learn more I’d suggest lurking / asking questions on postgres-specific forums, people there would be more knowledgeable about this type of questions and would probably provide you with better answers.