3 ms·
I'd love to see this in blog post form! This seems like a case where it would be nice to be able to pass in a parameter `vals (x, y)`.
by acjohnson55 4y ago
I'd love to see this in blog post form!
This seems like a case where it would be nice to be able to pass in a parameter `vals (x, y)`.
- Izkata 4y agoI've tried to get myself writing a few times but never succeeded, so I don't have a blog. But - I am actually doing parameters like so in the view where I copied the above from: CREATE TABLE view_confs (key, value); INSERT INTO view_confs VALUE ('start', 2), ('end', 4); Now prefix it with another one: vals_range(x, y) AS ( SELECT x, y FROM vals WHERE x >= (SELECT value FROM view_confs WHERE key = 'start') AND x < (SELECT value FROM view_confs WHERE key = 'end') ), And swap the rest of the original query to use "vals_range" instead of "vals". Just gotta remember to update view_confs with the new range whenever you want to change the view. I think it should work inside a transaction to avoid multiple threads interfering with each other, but also to be clear: This is a workaround for sqlite not having stored procedures, and not wanting to implement it in code (so I can JOIN to the view in other queries). Better to use stored procedures in other databases than this workaround.