Is this valid sql? "select count(*) usertable;"
Describe the problem
More of a syntax question...
Ran the following statement without a from...
select count(*) usertable;
got the following.
root@localhost:26257/ycsb> select count(*) usertable; usertable +-----------+ 1
Seems rather liberal, but perhaps this is valid sql...
To Reproduce
select count(*) usertable; If possible, provide steps to reproduce the behavior:
Environment:
- CockroachDB version v19.1.3
- Server OS: Mac OSX 10.13.6
- Client app [e.g.
cockroach sql, JDBC, ...]
Hey @jesterjaimi
The SELECT COUNT(*) is using an implicit AS in your query, and since a table is not being selected from, there's a "unit" table that is implicitly using a column named "usertable" with value of 1. You can see below that the first and second queries give the same result, versus the correct syntax for the count from table "usertable".
root@:26257/ycsb> SELECT COUNT(*) usertable;
usertable
+-----------+
1
(1 row)
Time: 455µs
root@:26257/ycsb> SELECT COUNT(*) AS usertable;
usertable
+-----------+
1
(1 row)
Time: 511µs
root@:26257/ycsb> SELECT COUNT(*) FROM usertable;
count
+-------+
10000
(1 row)
Time: 6.467ms
Let me know if there are any other questions.
Cheers, Ricardo
Hey @jesterjaimi
Did you have any other questions on this issue?
Cheers, Ricardo