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

Support Array of citext citext[] column #970

Open
jwoertink opened this issue Sep 11, 2023 · 2 comments · May be fixed by #972
Open

Support Array of citext citext[] column #970

jwoertink opened this issue Sep 11, 2023 · 2 comments · May be fixed by #972
Labels
hacktoberfest Valid Issue for Hacktoberfest

Comments

@jwoertink
Copy link
Member

Avram currently supports Array(String), but if you need to search an array with case insensitive, then things get a little hairy

(assuming you have a GIN index on this column...)

=# select username from users where tags @> array['Lucky'];
  username   
-------------
 jeremy
(1 row)

Time: 0.438 ms
=# select username from users where tags @> array['LUCKY'];
  username   
-------------
(0 rows)

Time: 0.815 ms
=# select username from users where lower(tags::text)::text[] @> array['lucky'];
  username   
-------------
 jeremy
(1 row)

Time: 36.088 ms

Now if you use a citext[] column instead..

=# select username from users where tags @> array['LUCKY']::citext[];
  username   
-------------
 jeremy
(1 row)

Time: 0.395 ms
=# select username from users where tags @> array['lUcKy']::citext[];
  username   
-------------
 jeremy
(1 row)

Time: 0.408 ms
@jwoertink
Copy link
Member Author

Ok, so apparently this is sort of supported already 🤯 You can create the column in your migrations already

alter table_for(User) do
  add tags : Array(String), default: [] of String, case_sensitive: false
end

table do
  column tags : Array(String)
end

Though, if you try to query with the column, you'll run in to some errors:

UserQuery.new.tags.includes("lucky").first
# Unhandled exception: Can't read column of type Array(Slice(UInt8)) as Array(String) (PG::RuntimeError)

I'm guessing some casting somewhere has to happen...

@jwoertink
Copy link
Member Author

We may not be able to add this in until we get will/crystal-pg#250

@jwoertink jwoertink linked a pull request Sep 13, 2023 that will close this issue
@jwoertink jwoertink added the hacktoberfest Valid Issue for Hacktoberfest label Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest Valid Issue for Hacktoberfest
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant