ruby-on-railspostgresqlactiverecordruby-on-rails-5ruby-on-rails-6

Postgres: What does @@ (double at symbol) mean?


Recently I've found a piece of code for ruby on rails which should search string like like-operator:

scope :search, -> (query) { where('name @@ :q', q: query) }

But couldn't find any documentation about it.

The operator doesn't work as expected. So what exactly it does?


Solution

  • It's a text search, check out documentation.

    If you'd rather not go somewhere else for an answer, here:

    The @@ operator in PostgreSQL is related to the full-text search capabilities provided by the tsquery and tsvector types. The @@ operator is used to compare a tsquery value (the query) with a tsvector value (the document) to determine if the document matches the query.

    The tsvector type represents a document processed for full-text search, while the tsquery type represents a query in a format suitable for searching in tsvector documents. The @@ operator returns true if the query matches the document, and false otherwise.