From: | Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com> |
---|---|
To: | pgsql-docs <pgsql-docs(at)postgresql(dot)org> |
Subject: | updatable cursors and ORDER BY |
Date: | 2018-05-10 02:43:43 |
Message-ID: | fa0e80d3-a734-4db1-cf66-fe6d3a6c043b@2ndquadrant.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-docs |
The DECLARE reference page says:
"""
Another reason to use FOR UPDATE is that without it, a subsequent WHERE
CURRENT OF might fail if the cursor query does not meet the SQL
standard's rules for being “simply updatable” (in particular, the cursor
must reference just one table and not use grouping or ORDER BY). Cursors
that are not simply updatable might work, or might not, depending on
plan choice details; so in the worst case, an application might work in
testing and then fail in production.
"""
Indeed, grouping in cursors declared FOR UPDATE is rejected:
DECLARE c CURSOR FOR SELECT f1,count(*) FROM uctest GROUP BY f1 FOR UPDATE;
ERROR: FOR UPDATE is not allowed with GROUP BY clause
But ORDER BY is allowed, contrary to what that note appears to say:
DECLARE c CURSOR FOR SELECT f1, f2 FROM uctest ORDER BY f1 FOR UPDATE;
-- no error, works fine
Is this note outdated? A brief look into history of
CheckSelectLocking() suggests that it might never have been correct.
--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2018-05-10 02:57:25 | Re: updatable cursors and ORDER BY |
Previous Message | Martín Marqués | 2018-05-09 23:59:15 | Re: Mistakes between an example and its description |