HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

Match all in a full text search

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
fullsearchalltextmatch

Problem

Using PostgreSQL 9.4, is there anyway that we can specify the tsquery to match all?

I have tried:

SELECT 'a fat cat sat on a mat and ate a fat rat'::tsvector @@ '*'::tsquery;


But it doesn't seem to work. It returns false.

Solution

Wrap you expression in a CASE statement:

SELECT * FROM tbl
WHERE  CASE $1 WHEN '*' THEN TRUE
       ELSE some_tsvector_column @@ $1::tsquery END;


This way you can pass '*' to disable the filter or any other valid tsquery string to actually filter.

Code Snippets

SELECT * FROM tbl
WHERE  CASE $1 WHEN '*' THEN TRUE
       ELSE some_tsvector_column @@ $1::tsquery END;

Context

StackExchange Database Administrators Q#97512, answer score: 4

Revisions (0)

No revisions yet.