Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1UmOFd-00035i-Tj for pgsql-bugs@arkaria.postgresql.org; Tue, 11 Jun 2013 13:04:42 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1UmOFd-0008Gy-Dv for pgsql-bugs@arkaria.postgresql.org; Tue, 11 Jun 2013 13:04:41 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UmOFc-0008GW-MU for pgsql-bugs@postgresql.org; Tue, 11 Jun 2013 13:04:40 +0000 Received: from szxga02-in.huawei.com ([119.145.14.65]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1UmOFV-0006yN-Cc for pgsql-bugs@postgresql.org; Tue, 11 Jun 2013 13:04:40 +0000 Received: from 172.24.2.119 (EHLO szxeml211-edg.china.huawei.com) ([172.24.2.119]) by szxrg02-dlp.huawei.com (MOS 4.3.4-GA FastPath queued) with ESMTP id BDC97612; Tue, 11 Jun 2013 21:04:27 +0800 (CST) Received: from SZXEML455-HUB.china.huawei.com (10.82.67.198) by szxeml211-edg.china.huawei.com (172.24.2.182) with Microsoft SMTP Server (TLS) id 14.1.323.7; Tue, 11 Jun 2013 21:04:24 +0800 Received: from blrprnc09ns (10.18.96.98) by SZXEML455-HUB.china.huawei.com (10.82.67.198) with Microsoft SMTP Server id 14.1.323.7; Tue, 11 Jun 2013 21:04:21 +0800 From: Amit Kapila To: "'Tom Lane'" CC: "=?iso-8859-1?Q?'Brice_Andr=E9'?=" , References: <51a458f5.6196420a.30dc.3d58SMTPIN_ADDED_BROKEN@mx.google.com> <51a4aae6.cade440a.44ca.ffff81a1SMTPIN_ADDED_BROKEN@mx.google.com> <00b101ce5bb3$840448f0$8c0cdad0$@kapila@huawei.com> <27432.1370889926@sss.pgh.pa.us> In-Reply-To: <27432.1370889926@sss.pgh.pa.us> Subject: Re: bug in Prepared statement with DELETE RETURNING and rule on view Date: Tue, 11 Jun 2013 18:34:20 +0530 Message-ID: <008801ce66a4$30a34840$91e9d8c0$@kapila@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook 12.0 Thread-Index: Ac5mCq5ICy1PcPs5T3aABI94bFG4UgAlPwhw Content-Language: en-us X-Originating-IP: [10.18.96.98] X-CFilter-Loop: Reflected X-Pg-Spam-Score: 0.9 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org On Tuesday, June 11, 2013 12:15 AM Tom Lane wrote: > [ got around to looking at this thread finally ] > > Amit Kapila writes: > > What happens when you change ON DELETE rule of the view that really > deletes > > elements is that command type after applying rule remains same which > means > > Delete, so it can set the Tag. > > The point here is that in extended-query mode, we've defined that only > the same statement that sets the command tag can return RETURNING rows. > In the case at hand, the original DELETE isn't executed at all, being > replaced by an UPDATE according to the rule. But we don't change the > returned command tag to UPDATE, and we don't let the UPDATE's RETURNING > clause return anything to the client. Both of these rules are meant to > ensure unsurprising behavior as seen from the client side. We could > debate changing them, but I'd be pretty worried about breaking user > applications if we did. There are only 2 points I could think of supporting such behavior: 1. Explain on Delete statement will show Update, so returning command tag as Update is not wrong. 2. Maintaining consistency between psql and client interface. I think user's have facility to obtain information about prepared statement by using PQdescribePrepared() to know what they could expect in result. > At the same time, things don't look terribly consistent because in psql > (which uses simple query protocol) you *do* see the RETURNING results. > That's because simple query protocol doesn't have a restriction that > only one resultset can be returned from a single query. So it's a lot > more wild-west as to what will really happen, and application code is > expected to just deal with that. psql doesn't have a problem with > multiple query results because it doesn't particularly care what they > are; it's just going to print each one. Apps that are supposed to > actually make sense of the data have more of an issue with that. The > extended query protocol was explicitly designed to lock things down > better so that interactions would be more predictable. > > The main thing I'm noticing in looking at this is that the > documentation > doesn't seem to explain anywhere the restriction to getting RETURNING > results back from only the primary query. We ought to fix that. I could think of below text that can be mentioned either in Create Rule (Notes Section) page or in Extended Query section: For extended-query mode, if the RULE changes the original statement, command tag will not be modified and RETURNING clause will not return rows. With Regards, Amit Kapila. -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs