-
Notifications
You must be signed in to change notification settings - Fork 661
Milestone
Description
SQLite special-cases bare columns (unaggregated columns that aren't functionally dependent on aggregated columns). From the documentation:
Special processing occurs when the aggregate function is either min() or max(). (...) If there is exactly one min() or max() aggregate in the query, then all bare columns in the result set take values from an input row which also contains the minimum or maximum. [... see the rest for more details]
Turso doesn't seem to have this special-case handling:
turso> create table t(a,b,c);
turso> insert into t values (1, 'a', 'a'), (1, 'b', 'b'), (1, 'c', 'c');
turso> select a, b, max(c) from t group by a; -- b column is incorrect
┌───┬───┬───────────┐
│ a │ b │ max (t.c) │
├───┼───┼───────────┤
│ 1 │ a │ c │
└───┴───┴───────────┘
turso> select a, b, min(c) from t group by a; -- this one happens to be correct
┌───┬───┬───────────┐
│ a │ b │ min (t.c) │
├───┼───┼───────────┤
│ 1 │ a │ a │
└───┴───┴───────────┘
SQLite, for comparison:
sqlite> create table t(a,b,c);
sqlite> insert into t values (1, 'a', 'a'), (1, 'b', 'b'), (1, 'c', 'c');
sqlite> select a, b, max(c) from t group by a;
1|c|c
sqlite> select a, b, min(c) from t group by a;
1|a|a
Metadata
Metadata
Assignees
Labels
No labels