Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

PostgreSQL SKIP LOCKED

If you need to SELECT from a table and protect those rows from being updated until your transaction has completed, you would specify FOR UPDATE, but if some rows are locked, you can specify SKIP LOCKED to tell it to simply ignore those rows and just perform the operation on whichever rows it can access.

For example:
In session 1:
 # BEGIN;
 BEGIN
 # SELECT * FROM colours;
  id | name  
 ----+-------
   1 | red
   2 | green
   3 | blue
 (3 rows)
 # UPDATE colours SET name = 'scarlet' WHERE name = 'red';
 CREATE TABLE
In session 2:
 # SELECT * FROM colours FOR UPDATE NOWAIT;
 ERROR:  could not obtain lock on row in relation "colours"
 # SELECT * FROM colours FOR UPDATE SKIP LOCKED;
  id | name  
 ----+-------
   2 | green
   3 | blue
 (2 rows)

Comments

Popular posts from this blog

Oracle DBMS SCHEDULER Examples

How to find the server is whether standby (slave) or primary(master) in Postgresql replication ?

7 Steps to configure BDR replication in postgresql

How to Get Table Size, Database Size, Indexes Size, schema Size, Tablespace Size, column Size in PostgreSQL Database

vacuumlo - removing large objects orphans from a database PostgreSQL