saialluru
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
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries.
offset-based pagination with...
New
I needed to reuse React components from my Chrome extension in my Phoenix/LiveView backend. I noticed that for Svelte/Vue, there are live...
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 all!
I want to present a small library which provides a mix task for generating an Entity-Relationship Diagram for Ecto schemas.
You...
New
Hello
Published a new library - ProcessHub!
ProcessHub is a library designed to manage process distribution within the Elixir cluster. ...
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
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
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
New
This showed up on my feed.. anyone heard of it? Just hype?
Ox Alpha is a reasoning model designed for coding, sustained ag...
New
It’s not that it’s vocabulary is too advanced. It’s something worse.
I get lost trying to follow even a paragraph written by Claude. It’...
New
Today we’re releasing Oban for Python. Not an Oban client in Python. Not a pythonx wrapper embedded in Elixir. Nope, it’s a fully operati...
New
@hugobarauna, Dr. Dimitrios Koutmos (my brother) and I (Alex Koutmos) have been hard at work on writing a book on how you can use Elixir ...
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 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
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.saialluru
The table I have is
CREATE TABLE IF NOT EXISTS public.default_name
(
subject character(15) COLLATE pg_catalog.“default” NOT NULL,
validity int4range,
object character(15) COLLATE pg_catalog.“default”,
CONSTRAINT default_name_subject_validity_excl EXCLUDE USING gist (
subject WITH =,
validity WITH &&)
)
The samples I want to execute using SQL are
insert into default_name values (‘Sai’, ‘[0,)’::int4range, ‘Alluru’);
followed by an update
UPDATE default_name SET
validity = int4range(lower(validity), 10, ‘[)’)
where subject = ‘Sai’ and validity @> 10
This works fine in Postgres unable figure out how to get this working on Using Repo.SQL
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
saialluru
I am not using Ecto Schema I need tables to be created a run time, so want to just use plain SQL with prepared statements. By the I am very new to Elixir and the tools.
ruslandoga
I’m not suggesting Ecto Schema.
saialluru
Ok how about the update statement ?
ruslandoga
You can use
Repo.update_all.saialluru
I will try, Is it the standard bahavior that errors are not properly reported.
saialluru
Insert worked, thanks a lot I am assuming I can pass a list of objects for batch insert.Which I will try.
saialluru
For update I just want to update the upper bound, I have no idea about the lower bound at that time, so do I not specify the lower in the Range and only specify upper., Would that work ?