-
Notifications
You must be signed in to change notification settings - Fork 270
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
type regconfig
can not be handled by the types module Postgrex.DefaultTypes
#502
Comments
Correct. Postgrex doesn’t support all possible PG types, especially because they can be provided by extensions. In this case, you have to create your own Modules to handle this. See Postgrex docs. Odds are that someone has already done it, so please search existing packages. :) |
The original approach to search in GIN indexes is to use `to_tsvector(text)` in the WHERE clause of the query. According to postgres docs [pdoc], this method does not make use of the index, while `to_tsvector(config, text)` does. This commit changed the query to use the two-argument `to_tsvector()`. [pdoc]: https://www.postgresql.org/docs/12/textsearch-tables.html To obtain the search config in use, we make a query to the db first. The `::regconfig::oid` hack is needed because Postgrex does not support regconfig type directly [postgrexbug]. I use the conversion from and to `oid` instead of `text` because I tested in the actual DB and querying using the conversion via `text` is slow just as the one-argument `to_tsvector()` variant. [postgrexbug]: elixir-ecto/postgrex#502 BUG: https://git.pleroma.social/pleroma/pleroma/-/issues/2758
The original approach to search in GIN indexes is to use `to_tsvector(text)` in the WHERE clause of the query. According to postgres docs [pdoc], this method does not make use of the index, while `to_tsvector(config, text)` does. This commit changed the query to use the two-argument `to_tsvector()`. [pdoc]: https://www.postgresql.org/docs/12/textsearch-tables.html To obtain the search config in use, we make a query to the db first. The `::regconfig::oid` hack is needed because Postgrex does not support regconfig type directly [postgrexbug]. I use the conversion from and to `oid` instead of `text` because I tested in the actual DB and querying using the conversion via `text` is slow just as the one-argument `to_tsvector()` variant. [postgrexbug]: elixir-ecto/postgrex#502 Backport of: https://git.pleroma.social/pleroma/pleroma/-/merge_requests/3519 Closes: https://git.pleroma.social/pleroma/pleroma/-/issues/2758
I'm curious to know if anybody has written an extension for |
Just an FYI for the future: In certain cases, you can use a trick to make Postgrex work with def search_comment_content(language, search_term) do
query = from(c in Comment, where: fragment("content @@ plainto_tsquery(?, ?)", ^language, ^search_term)
Repo.all(query)
end Postgrex doesn't know how to translate the
So, the trick is to type cast your def search_comment_content(language, search_term) do
query = from(c in Comment, where: fragment("content @@ plainto_tsquery(?::text::regconfig, ?)", ^language, ^search_term)
Repo.all(query)
end This way, Postgrex will transmit the |
For some context, ^ works because the result is a boolean. But if the result is a type that is unknown to Postgrex the error happens:
|
For posterity: I've created a small library that can enable text encoding for any data type in Postgrex: https://github.com/greg-rychlewski/postgrex_text_ext. This works well with OID types like |
PostgreSQL 12.2
Postgrex 0.15.3
Can not use text search configurations passed via raw query parameters:
Same query works from psql:
The text was updated successfully, but these errors were encountered: