Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array support #7

Open
thure opened this issue Dec 21, 2020 · 4 comments · May be fixed by #14
Open

Array support #7

thure opened this issue Dec 21, 2020 · 4 comments · May be fixed by #14
Assignees

Comments

@thure
Copy link

thure commented Dec 21, 2020

I've appreciated this library a ton.

Seems however that it's missing or now needs to implement array support for lquery and possibly ltree in order to support operations that take arrays as arguments: elixir-ecto/postgrex#528.

I'd be willlilng to help, but I'm totally unfamiliar with how Postgres communicates with Ecto. Is there a model for encoding/decoding arrays of this type I could use to create a PR, if one would be welcome?

@josemrb
Copy link
Owner

josemrb commented Dec 21, 2020

Hi @thure

Thanks for the report, I didn't know about this problem.

Seems however that it's missing or now needs to implement array support for lquery and possibly ltree in order to support operations that take arrays as arguments: elixir-ecto/postgrex#528.

Can you show me an example query with this issue?

I'd be willlilng to help, but I'm totally unfamiliar with how Postgres communicates with Ecto. Is there a model for encoding/decoding arrays of this type I could use to create a PR, if one would be welcome?

I'm still not sure what needs to be done but PRs are welcome :)

@josemrb josemrb self-assigned this Dec 21, 2020
@thure
Copy link
Author

thure commented Dec 21, 2020

Can you show me an example query with this issue?

If I use code like this:

lqueries = ["some.path", "other.path"]
from(
   bt in BallotTree,
   where: fragment("? \\? ?", bt.path, ^lqueries),
   select: sum(bt.vote_power)
 )
 |> Repo.all()

It gets translated to this SQL:

SELECT sum(c0."vote_power") FROM "cached_stv_scott_ballot_trees" AS c0 WHERE (c0."path" ? $2) [["some.path", "other.path"]]

But it errors with:

[error] Postgrex.Protocol (#PID<0.1320.0>) disconnected: ** (Postgrex.QueryError) type `_lquery` can not be handled by the types module Accord.PostgresTypes

…which seems like it knows that this is an array of the correct type, given Postgres prepends a type with an underscore in those cases, it just doesn't handle encoding/decoding arrays of these types.

Has EctoLtree been tested with ltree array opererators like ?, <@, etc?

@warmwaffles
Copy link
Contributor

warmwaffles commented Mar 29, 2022

I've been digging into this issue and I think it's not going to be possible.

I'm fairly certain, it will need an upstream addition to postgrex to fix the _ prefixing issue.

@greg-rychlewski greg-rychlewski linked a pull request Dec 17, 2022 that will close this issue
@gaslit
Copy link

gaslit commented Oct 9, 2023

Hello, may i know if this issue is fixable w a PR as above? Many thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants