I want to create a for update
select statement in Java using JDBC, but not sure how it would be done.
If you are unfamiliar with for update you can read about it here https://www.postgresql.org/docs/9.0/static/sql-select.html#SQL-FOR-UPDATE-SHARE
For example, I have the following select statements
My select statement
select email from email_accounts where already_linked = false order by random() limit 1
My update statement
UPDATE email_accounts set already_linked = true, account_link_timestamp = now() where email = ?
How would this be done in Java using JDBC while using for update
?
conn.setAutoCommit = false
necessary for thefor update
locks to be effective, or does it not matter? – Inkster