Skip to content

Instantly share code, notes, and snippets.

@Bahanix
Last active April 5, 2018 11:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Bahanix/4095d5bbf95a102280e045fe76c7d184 to your computer and use it in GitHub Desktop.
Save Bahanix/4095d5bbf95a102280e045fe76c7d184 to your computer and use it in GitHub Desktop.
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