Does a row lock taken out in a CTE stay in place?

From: Seamus Abshere <seamus(at)abshere(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Does a row lock taken out in a CTE stay in place?
Date: 2017-07-11 15:36:17
Message-ID: 1499787377.3420973.1037421528.6AC1E2E3@webmail.messagingengine.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Given an update that uses CTEs like this:

WITH
lock_rows AS (
SELECT 1 FROM tbl WHERE [...] FOR UPDATE
)
UPDATE [...]

Will the rows in `tbl` remain locked until the UPDATE is finished?

Also, does it matter if `lock_rows` is referenced? (IIUC the query
wouldn't be run if the CTE isn't referenced if it was for a SELECT, but
since it's an UPDATE, it will be run anyway)

Thanks!
Seamus

--
Seamus Abshere, SCEA
https://github.com/seamusabshere
https://linkedin.com/in/seamusabshere
https://www.faraday.io

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2017-07-11 15:45:45 Re: Does a row lock taken out in a CTE stay in place?
Previous Message dandl 2017-07-11 13:58:15 Re: Imperative Query Languages