Colton Idle
10/19/2023, 2:22 PMsizeOfTable:
SELECT COUNT(*);
but open to other ideas if anyone knows better. 😅Benoit Quenaudon
10/19/2023, 2:24 PMjw
10/19/2023, 2:25 PM== 0
to get a booleanColton Idle
10/19/2023, 2:49 PMtableIsEmpty:
SELECT COUNT(*) FROM myDbTable LIMIT 1 == 0;
would work...jw
10/19/2023, 2:53 PMLIMIT false
COUNT(*)
is always optimized to O(1) so there's nothing to improve upon here except possibly returning the boolean directly rather than doing it in code.COUNT(column_in_index)
, but not anymore.Colton Idle
10/19/2023, 3:04 PMjw
10/19/2023, 3:07 PMFROM
in thereColton Idle
10/19/2023, 3:12 PMsaket
10/19/2023, 3:25 PMSELECT COUNT(*) == 0
even worksjw
10/19/2023, 3:31 PMsqlite> SELECT COUNT(*);
1
sqlite> EXPLAIN QUERY PLAN SELECT COUNT(*);
QUERY PLAN
`--SCAN CONSTANT ROW
sqlite> EXPLAIN SELECT COUNT(*);
addr opcode p1 p2 p3 p4 p5 comment
---- ------------- ---- ---- ---- ------------- -- -------------
0 Init 0 1 0 0 Start at 1
1 Null 0 1 1 0 r[1..1]=NULL
2 AggStep 0 0 1 count(0) 0 accum=r[1] step(r[0])
3 AggFinal 1 0 0 count(0) 0 accum=r[1] N=0
4 Copy 1 2 0 0 r[2]=r[1]
5 ResultRow 2 1 0 0 output=r[2]
6 Halt 0 0 0 0
weirdSELECT *;
it yells. SELECT COUNT(0);
is 1, but not sure why SELECT COUNT(*);
works...ephemient
10/19/2023, 6:31 PMSELECT COUNT(*)
of any table (regardless of number of columns) is fine but SELECT *
of a zero-column table isn't, I guess?jessewilson
10/20/2023, 5:11 AM