The following bug has been logged on the website:
Bug reference: 14515
Logged by: Tom Dunstan
Email address: pgsql(at)tomd(dot)cc
PostgreSQL version: 9.5.5
Operating system: Linux
Not sure if this is a bug or just ambiguity in the docs, but I certainly
found it counter-intuitive.
Basically while `select 'somethingelse'::tsvector @@ '!foo'::tsquery`
returns true, `select ''::tsvector @@ '!foo'::tsquery` returns false, which
was surprising to me.
I would expect a tsvector (empty or not) that doesn't contain foo to match
It seems like the behaviour is "match a term that isn't foo" rather than
"match if no terms match foo".
Not sure if this is intentional (in which case maybe the docs could be a bit
more clear) or if it's just a bug. IMO the former behaviour isn't very
useful as it forces us to either code around it by writing extra SQL to
handle the case, or insert a dummy term to match against. Neither is very
It may be unintentional: there's a fast-path out of the match function here
that returns false when the vector is empty. Perhaps it just wasn't taking
the negative-only case into account.
pgsql-bugs by date
|Next:||From: Tom Lane||Date: 2017-01-26 03:32:28|
|Subject: Re: BUG #14515: tsquery with only a negative term doesn't match empty tsvector|
|Previous:||From: Fabien COELHO||Date: 2017-01-25 17:59:45|
|Subject: Re: Problem in using pgbench's --connect(-C) and --rate=rate(-R
rate) options together.|