Sample Header Ad - 728x90

Postgres UPDATE ... LIMIT 1

152 votes
1 answer
199466 views
I have a Postgres database which contains details on clusters of servers, such as server status ('active', 'standby' etc). Active servers at any time may need to fail over to a standby, and I don't care which standby is used in particular. I want a database query to change the status of a standby - JUST ONE - and return the server IP that is to be used. The pick can be arbitrary: since the status of the server changes with the query, it doesn't matter which standby is selected. Is it possible to limit my query to just one update? Here is what I have so far: UPDATE server_info SET status = 'active' WHERE status = 'standby' [[LIMIT 1???]] RETURNING server_ip; Postgres doesn't like this. What could I do differently?
Asked by vastlysuperiorman (1695 rep)
Jul 1, 2014, 04:54 PM
Last activity: May 3, 2024, 09:23 PM