4 ms·
I know this isn't central to your point, but I thought I'd say it anyway. These days I have taken to doing: sql = "SELECT * FROM products WHERE TRUE" .
by adrianmsmith 12y ago
I know this isn't central to your point, but I thought I'd say it anyway. These days I have taken to doing:
sql = "SELECT * FROM products WHERE TRUE"
....
if upc:
sql += ' AND upc LIKE %?%'
....
This saves having to worry about "AND" and "WHERE", and the extra "WHERE TRUE" results in the same execution plan (thus the same performance).
- clebio 12y agoAwesome. That's such a straight-forward solution to one of the crappy edge-cases that SQL is so bad about (ending lists without commas, like JSON requires too, being another).
- chaz 12y agoI also add an extra column to my SELECTS: SELECT users.id, users.email, 1 FROM users I can just use "--" to comment out any line without having to manage the last comma. Especially useful when building aggregations.