cockroachdb / cockroach

CockroachDB — the cloud native, distributed SQL database designed for high availability, effortless scale, and control over data placement.
https://www.cockroachlabs.com
Other
30.11k stars 3.81k forks source link

QA: TSQuery parser cannot parse consecutive ! operators #98871

Open msirek opened 1 year ago

msirek commented 1 year ago

The TSQuery parser cannot handle consecutive ! (NOT) operators separated by whitespace, but this works in Postgres:

SELECT 'fats cats ate fat rats' @@ '! !(cats | bat & rats)'::tsquery;
ERROR: could not parse tsquery: syntax error in TSQuery: ! !(cats | bat & rats)
SQLSTATE: 42601

Wrapping the expression in parentheses works: SELECT 'fats cats ate fat rats' @@ '!(!(cats | bat & rats))'::tsquery;

Jira issue: CRDB-25562

msirek commented 1 year ago

Postgres also supports multiple ! operators with no whitespace in between, e.g.:

SELECT a FROM a WHERE a @@ '!!foo';
         a
-------------------
 'bar':4,5 'foo':3
 'foo':3

SELECT a FROM a WHERE a @@ '!!!foo';
         a
-------------------
 'baz':1
 'bar':2
 'sdf':2
 'sdfbar':2
 'bar':4,5 'sdf':3
 'sdf':2
(6 rows)

SELECT a FROM a WHERE a @@ '!!!!foo';
         a
-------------------
 'bar':4,5 'foo':3
 'foo':3
(2 rows)