Hi,

I mistakenly used the wrong side of the ON caluse in a group by clause for a 
query and I was wondering why SQLite didn't return the same results always:
-     SELECT SUM(x) FROM (SELECT files.size + LENGTH(CAST(files.name AS BLOB)) 
+ SUM(COALESCE(LENGTH(CAST(fmeta.key AS BLOB)) + LENGTH(fmeta.value),0)) AS x 
FROM files LEFT JOIN fmeta ON files.fid = fmeta.file_id WHERE files.volume_id = 
:volid AND age >= 0 GROUP BY fmeta.file_id
+       SELECT SUM(x) FROM (SELECT files.size + LENGTH(CAST(files.name AS 
BLOB)) + SUM(COALESCE(LENGTH(CAST(fmeta.key AS BLOB)) + LENGTH(fmeta.value),0)) 
AS x FROM files LEFT JOIN fmeta ON files.fid = fmeta.file_id WHERE 
files.volume_id = :volid AND age >= 0 GROUP BY files.fid

Then I realized that fmeta.file_id can be NULL, and then it no longer groups by 
file id and just selects a random row as documented:
"If the expression is an aggregate expression, it is evaluated across all rows 
in the group. Otherwise, it is evaluated against a single arbitrarily chosen 
row from within the group. "

Is there a way I could programatically determine that a query is 
non-deterministic at query prepare time?

-- 
Edwin T?r?k | Co-founder and Lead Developer

Skylable open-source object storage: reliable, fast, secure
http://www.skylable.com

Reply via email to