thenrio
I have an Ecto.Type Size that maps to postgres composite type size.
I can encode a Size parameter but can’t encode an array of Size.
Here some details, the postgres type
CREATE TYPE size AS (value numeric, unit varchar(255))
The Ecto.Type has a basic implementation, type/1, cast/1, dump/1 and load/1 (I omit the details).
Encode a Size parameter works (A):
> q = from(d in Display, where: d.size == type(^s43, Size) and d.id == 1440, select: d.id); Repo.to_sql(:all, q)
{"SELECT d0.\"id\" FROM \"displays\" AS d0 WHERE ((d0.\"size\" = $1::size) AND (d0.\"id\" = 1440))",
[{43, "inch"}]}
> Repo.all(q)
[1440]
But encode an array of Size does not (B):
q = from(d in Display, where: d.size in type(^[{43, "inch"}], {:array, Size}) and d.id == 1440, select: d.id); Repo.to_sql(:all, q)
{"SELECT d0.\"id\" FROM \"displays\" AS d0 WHERE (d0.\"size\" = ANY($1) AND (d0.\"id\" = 1440))",
[[{43, "inch"}]]}
Repo.all(q)
** (DBConnection.EncodeError) cannot encode anonymous tuple {43, "inch"}. Please define a custom Postgrex extension that matches on its underlying type:
use Postgrex.BinaryExtension, type: "typeinthedb"
It looks like some typing was lost there, when I use {:array, Size}, I want to mean size[].
Note that provide explicit cast of param to size[] works, at the sql level:
Repo.query!("select id from displays where size=any($1::size[]) and id=1440", [[{43, "inch"}]]).rows
[[1440]]
Is there something missing in my ecto expression (B)?
Trending in Questions
Hey guys,
I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly
Do you guys have any suggestions what is the best prac...
New
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
New
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
Hello,
I’m developing a online persistent chat system (what’s app) like using elixir/dynamodb/aws for a mobile app(flutter).
The diffic...
New
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
Anyone here using Honeybadger?
My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of
Bandit.HTTPError...
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
Other Trending Topics
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
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
There are three potential reasons for members of this forum to have a look at https://vutuv.de
You are tired or annoyed of LinkedIn.
Yo...
New
Aludel - LLM Evaluation Workbench
Aludel is an embeddable Phoenix LiveView dashboard for evaluating and comparing LLM prompts across mult...
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
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixir-ls
- #ai
- #elixirconf-us
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 2- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
thenrio
A containment is fragment:
dimitarvp
Problem seems to be that
postgrexdoes not know how to handle{43, "inch"}i.e. it does not map it to thesizetype – when it’s in a list / array that is.You already arrived at a good workaround IMO. But let’s list some more options:
(A)
Use
fragmentsimilar to what you already did:I have not tested this, just going by memory and docs. Should work but, you know, famous last words.
(B)
Define a custom type through
Postgrex.BinaryExtensionas the error message is guiding you to do; more or less write a small extension forpostgrex. You’ll have to implement a protocol and make sure the PostgreSQL extension is loaded on startup. None of these are a big problem but still, good to know what you are getting yourself into.I’d be tempted to just try this with
Ecto.Typebut we’re talking the wire protocol details here, not a transparent serialization of a type that’s a composite of others that are already well-handled.All of that being said, your escape hatch is IMO quite fine.