When dynamically generating WHERE
clauses for my sql, I like to hardcode WHERE '1' = '1'
into the sql so I don't have to track whether to prepend AND
to each following clause. This is well documented in many places, such as this stackoverflow question.
Is there an equivalent pattern for dynamically generating the SET
clause for UPDATE
statements? I rather not keep track of whether I need to prepend a comma or not. In case there aren't any general solutions, this will be for interacting with an oracle database over jdbc.
EDIT For my particular use case, I will need to dynamically change which columns are being set. So any solution which requires the query to contain all columns being set is a no go. We have a table with 20+ columns, but only 3 or 4 will change at any given time. We ran some load tests and found the only way to meet performance goals was to just send in data that needs to be updated. Now I'm just trying to write pretty code to do so.