2 ms·
Tagential thing I learned from your blog post: > The max(t1.date) and group by t1.state is a useful SQLite trick[0]: if you perform a group by and then ask for
by danso 5y ago
Tagential thing I learned from your blog post:
> The max(t1.date) and group by t1.state is a useful SQLite trick[0]: if you perform a group by and then ask for the max() of a value, the other columns returned from that table will be the columns for the row that contains that maximum value.
I had no idea that "bare columns" were an actual advertised feature of SQLite — I just assumed the bare column results were a happy accident (a consequence of SQLite's easy-going conventions) that seems to work (i.e. not throw an error) — but should otherwise be avoided, especially as it can't be depended on when migrating to stricter standards like pgsql or bigquery.
I'll think I'll continue to avoid it, but good to know that the seemingly correct-by-coincidence results are actually by intentional design.
[0] https://www.sqlite.org/draft/lang_select.html#bareagg https://www.sqlite.org/draft/lang_select.html#bareagg
- throwaway81523 5y agoYeah I remember noticing that too. I use it but will have to deal with some rewriting if I move my current sqlite stuff to another db. I'm not even sure what the best way to do it is.