From: | Daniele Varrazzo <daniele(dot)varrazzo(at)gmail(dot)com> |
---|---|
To: | "Vamsi Krishna Reddy -T (vamsredd - TATA CONSULTANCY SERVICES LIMITED at Cisco)" <vamsredd(at)cisco(dot)com> |
Cc: | "psycopg(at)postgresql(dot)org" <psycopg(at)postgresql(dot)org>, "Virag Jain (virajain)" <virajain(at)cisco(dot)com> |
Subject: | Re: How to lock a table for update and make other connections to wait on it |
Date: | 2015-07-09 17:24:58 |
Message-ID: | CA+mi_8Yq0JnMhUfJPOnp8qOegxd3wMa4Sjaxf_j4-2Gtkk1E0g@mail.gmail.com |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | psycopg |
On Thu, Jul 9, 2015 at 5:31 PM, 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)
>
You can use "INSERT ... RETURNING id" and avoid any concurrency issues.
http://www.postgresql.org/docs/9.3/static/sql-insert.html
-- Daniele
From | Date | Subject | |
---|---|---|---|
Next Message | Christophe Pettus | 2015-07-09 17:25:44 | Re: How to lock a table for update and make other connections to wait on it |
Previous Message | Vamsi Krishna Reddy -T (vamsredd - TATA CONSULTANCY SERVICES LIMITED at Cisco) | 2015-07-09 16:31:57 | How to lock a table for update and make other connections to wait on it |