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

Arrays not automatically supported? #528

Closed
thure opened this issue Dec 21, 2020 · 4 comments
Closed

Arrays not automatically supported? #528

thure opened this issue Dec 21, 2020 · 4 comments

Comments

@thure
Copy link

thure commented Dec 21, 2020

I'm using EctoLtree for a project, and when I try to query using an lquery array, I get

(Postgrex.QueryError) type `_lquery` can not be handled…

EctoLtree's extension for Postgrex defines lquery, but not the array type _lquery.

There doesn't appear to be any documentation about type extensions supporting arrays beyond:

Unlike most client libraries Postgrex uses the binary protocol, not the text protocol. This allows for efficient encoding of types (e.g. 4-byte integers are encoded as 4 bytes, not as a string of digits) and automatic support for arrays and composite types.

Does EctoLtree need to be extended to support lquery arrays, or is there a simpler fix? If it needs to be extended, is there an example in the ecosystem I could model the extension off of?

I'm using PostgreSQL 13, Erlang/OTP 23, Elixir 1.11.2, Postgrex 0.15.3.

@josevalim
Copy link
Member

Our arrays are modeled as recursive types so it should work unless ltree arrays are modeled with its own type, which may be the case here. Then you will need to teach Postgrex how to encode and decode it accordingly via custom extensions.

@thure
Copy link
Author

thure commented Dec 21, 2020

As far as I can tell, lquery[] is just a flat text array.

I'm not familiar with Postgrex's internals, so Postgrex.Extensions.Array is bewildering to me and relies on a lot of logic that seems out-of-scope for this use-case… is there a more straightforward model I could use?

@josevalim
Copy link
Member

As far as I can tell, lquery[] is just a flat text array.

The text representation is not necessarily the same as the binary representation, so the text representation cannot be used as reference. The first question you need to answer is how an array of lquery is encoded in the binary protocol and perhaps the best way to do this is to start your own extension based on lquery itself and inspect the data. Or find the PostgreSQL reference for this data type.

@thure
Copy link
Author

thure commented Dec 21, 2020

I'll work with the author of EctoLtree on this, thanks!

@thure thure closed this as completed Dec 21, 2020
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

No branches or pull requests

2 participants