Updated on 2025-05-29 GMT+08:00

Text Search Operators

@@

Description: Specifies whether the tsvector-typed words match the tsquery-typed words.

Example:

1
2
3
4
5
gaussdb=# SELECT to_tsvector('fat cats ate rats') @@ to_tsquery('cat & rat') AS RESULT;
 result 
--------
 t
(1 row)

@@@

Description: Synonym for @@

Example:

1
2
3
4
5
gaussdb=# SELECT to_tsvector('fat cats ate rats') @@@ to_tsquery('cat & rat') AS RESULT;
 result 
--------
 t
(1 row)

||

  • Description: Connects two tsvector-typed words.

    Example:

    1
    2
    3
    4
    5
    gaussdb=# SELECT 'a:1 b:2'::tsvector || 'c:1 d:2 b:3'::tsvector AS RESULT;
              result           
    ---------------------------
     'a':1 'b':2,5 'c':3 'd':4
    (1 row)
    
  • Description: Performs the OR operation on two tsquery-typed words.

    Example:

    1
    2
    3
    4
    5
    gaussdb=# SELECT 'fat | rat'::tsquery || 'cat'::tsquery AS RESULT;
              result           
    ---------------------------
     ( 'fat' | 'rat' ) | 'cat'
    (1 row)
    

&&

Description: Performs the AND operation on two tsquery-typed words.

Example:

1
2
3
4
5
gaussdb=# SELECT 'fat | rat'::tsquery && 'cat'::tsquery AS RESULT;
          result           
---------------------------
 ( 'fat' | 'rat' ) & 'cat'
(1 row)

!!

Description: Not a tsquery-typed word.

Example:

1
2
3
4
5
gaussdb=# SELECT !! 'cat'::tsquery AS RESULT;
 result 
--------
 !'cat'
(1 row)

@>

Description: Specifies whether a tsquery-typed word contains another tsquery-typed word.

Example:

1
2
3
4
5
gaussdb=# SELECT 'cat'::tsquery @> 'cat & rat'::tsquery AS RESULT;
 result 
--------
 f
(1 row)

<@

Description: Specifies whether a tsquery-typed word is contained in another tsquery-typed word.

Example:

1
2
3
4
5
gaussdb=# SELECT 'cat'::tsquery <@ 'cat & rat'::tsquery AS RESULT;
 result 
--------
 t
(1 row)

In addition to the preceding operators, the ordinary B-tree comparison operators (including = and <) are defined for types tsvector and tsquery.