Last active
April 5, 2018 11:39
-
-
Save Bahanix/4095d5bbf95a102280e045fe76c7d184 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_column :users, :tags, :string, array: true, null: false, default: [] | |
add_index :users, :tags, using: :gin | |
# Ceci ne fonctionnera pas : | |
User.where("users.tags @> ?", requested_tags) | |
# Faites ceci, même si requested_tags n'a qu'un item ou n'est pas un array. | |
User.where("users.tags @> ARRAY[?]", requested_tags) | |
# Si vous rencontrez cette erreur, faites ceci : | |
# ActiveRecord::StatementInvalid: PG::UndefinedFunction: ERROR: operator does not exist: character varying[] @> text[] | |
User.where("users.tags @> ARRAY[?]::varchar[]", requested_tags) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment