Re: How to lock a table for update and make other connections to wait on it

From: Christophe Pettus <xof(at)thebuild(dot)com>
To: "psycopg(at)postgresql(dot)org" <psycopg(at)postgresql(dot)org>
Subject: Re: How to lock a table for update and make other connections to wait on it
Date: 2015-07-09 17:25:44
Message-ID: BE307F8C-E958-4DFF-9695-BB73D3573F47@thebuild.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: psycopg


On Jul 9, 2015, at 9:31 AM, Vamsi Krishna Reddy -T (vamsredd - TATA CONSULTANCY SERVICES LIMITED at Cisco) <vamsredd(at)cisco(dot)com> wrote:

> 1. Insert a row to a table , using cursor.execute()
> 2. To fetch the row id of the above inserted data, we are using cursor.execute() to execute a sql command which fetches the max ‘id’ from the table (id is a column in the table which gets incremented on each insert)

Don't do it that way. Use the RETURNING clause on INSERT to get the inserted value.
--
-- Christophe Pettus
xof(at)thebuild(dot)com

In response to

Browse psycopg by date

  From Date Subject
Next Message Karsten Hilbert 2015-07-09 22:20:41 Re: How to lock a table for update and make other connections to wait on it
Previous Message Daniele Varrazzo 2015-07-09 17:24:58 Re: How to lock a table for update and make other connections to wait on it