-
-
Notifications
You must be signed in to change notification settings - Fork 264
Description
This issue was encountered while attempting to use Set as part of an UPDATE to a PostgreSQL database table.
In order to increment the value of an INT or BIGINT in a column in PostgreSQL, I can use:
UPDATE some_table
SET some_column = some_column + 1
WHERE some_other_column = 'change me';
The challenge is that Bun's Set always wraps single quotes around it's second parameter. Thus using Set("some_column = ?", "some_column + 1") in code becomes SET some_column = 'some_column + 1' in the UPDATE statement, which subsequently fails with an invalid input syntax for type error where the column is INT or BIGINT.
I'm assuming I'm missing something, so I'd appreciate pointers around the recommended approach for incrementing or decreasing column int values as part of an UPDATE.
Update
As a temporary measure I'm using a separate SELECT statement to scan the existing INT from the table into a currentValue var, incrementing that by one, then using that to setting the column value. It works, but it's not very elegant or efficient.