patternsqlMinor
Match all in a full text search
Viewed 0 times
fullsearchalltextmatch
Problem
Using PostgreSQL 9.4, is there anyway that we can specify the
I have tried:
But it doesn't seem to work. It returns
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
This way you can pass
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.