Another possible solution that will work on any table you have read access to regardless of whether it has one row, many rows, or even none at all:
SELECT toTimestamp(now()) AS now, count(*) FROM any_table WHERE partition_key=xyz;
The difference here is that the aggregate function COUNT(*)
guarantees that the result set will always contain exactly one row.
Obviously, replace any_table
with a table that you have read access to, and the WHERE clause with something that fully-specifies the table partition key. Again, there don't need to be any actual rows matching the specified value(s) for the partition key so any value(s) of the right type can be hard-coded.
Update
If the table has many rows, then count(*)
will take a long time to complete and may even time out, so use this method with caution.
Aside
dateof()
was deprecated in Cassandra 2.2.0-rc2. For later versions you should replace its use with toTimestamp()
.