Skip to content
← Back to activity

Immutable solution version

Is the OR operator supported in ScyllaDB?

Version 1Sign in to save

Complete solution

CQL (the Cassandra Query Language, also implemented by ScyllaDB), does not have a general-purpose "OR" keyword (see issue #12910 - only "AND" is supported).

CQL (the Cassandra Query Language, also implemented by ScyllaDB), does not have a general-purpose "OR" keyword (see issue #12910 - only "AND" is supported). The error message could have been, and should have been, friendlier (see issue #1703), but ultimately tells you the right thing - that it's a syntax error - OR is not legal CQL syntax. In your use case, where email='[recipient email]' or email='robs@ex', the solution is simple - just use the IN keyword: where email IN ('[recipient email]', 'robs@ex'). By the way, the 1=1 part also doesn't work, not even without OR, because currently CQL expressions are rather limited in their scope, in this case column=value is a valid expression, but value=value or other stuff, is not. Issue #12906 is one step towards improving that, but for your use case you don't really need it (you didn't really want to use 1=1 in your expression).

Context: Stack Overflow #75832433 (accepted answer, 6 votes): How does OR condition works in WHERE clause for SELECT statements in scylladb. I have created secondary index on email. Below query works fine and return result. `` cqlsh> select * from test.d_emp where email='[recipient email]'; id | dept | email | first_name | last_name | salary -----+------+-------------+------------+-----------+-------- 10 | 10 | [recipient email] | Rob | Stark | 1000 1 | 10 | [recipient email] | Rob | Stark | 1000 101 | 10 | [recipient email] | Rob | Stark | 1000 (3 rows) `` However if I use two conditions using OR operator it is giving syntax error. Even a simple 1=1...

Evidence

Source: Stack Overflow #75832433 (accepted answer, 6 votes): How does OR condition works in WHERE clause for SELECT statements in scylladb. I have created secondary index on email. Below query works fine and return result. `` cqlsh> select * from test.d_emp where email='[recipient email]'; id | dept | email | first_name | last_name | salary -----+------+-------------+------------+-----------+-------- 10 | 10 | [recipient email] | Rob | Stark | 1000 1 | 10 | [recipient email] | Rob | Stark | 1000 101 | 10 | [recipient email] | Rob | Stark | 1000 (3 rows) `` However if I use two conditions using OR operator it is giving syntax error. Even a simple 1=1...

Verified resolution: CQL (the Cassandra Query Language, also implemented by ScyllaDB), does not have a general-purpose "OR" keyword (see issue #12910 - only "AND" is supported). The error message could have been, and should have been, friendlier (see issue #1703), but ultimately tells you the right thing - that it's a syntax error - OR is not legal CQL syntax. In your use case, where email='[recipient email]' or email='robs@ex', the solution is simple - just use the IN keyword: where email IN ('[recipient email]', 'robs@ex'). By the way, the 1=1 part also doesn't work, not even without OR, because currently CQL expressions are rather limited in their scope, in this case column=value is a valid expression, but value=value or other stuff, is not. Issue #12906 is one step towards improving that, but for your use case you don't really need it (you didn't really want to use 1=1 in your expression).

Source URL: https://stackoverflow.com/questions/75832433/is-the-or-operator-supported-in-scylladb

By @issueatlas · Version 1 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_NQZ5fIBhEFXuXiO4V5iboQ" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Is the OR operator supported in ScyllaDB? <span>— Vectle</span></a>