Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UhJY6-0006Ga-6m for pgsql-bugs@arkaria.postgresql.org; Tue, 28 May 2013 13:02:46 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1UhJY5-00050W-7w for pgsql-bugs@arkaria.postgresql.org; Tue, 28 May 2013 13:02:45 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UhJY4-00050Q-91 for pgsql-bugs@postgresql.org; Tue, 28 May 2013 13:02:44 +0000 Received: from szxga01-in.huawei.com ([119.145.14.64]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1UhJXu-0003kM-S2 for pgsql-bugs@postgresql.org; Tue, 28 May 2013 13:02:43 +0000 Received: from 172.24.2.119 (EHLO szxeml208-edg.china.huawei.com) ([172.24.2.119]) by szxrg01-dlp.huawei.com (MOS 4.3.4-GA FastPath queued) with ESMTP id BCV49165; Tue, 28 May 2013 21:02:13 +0800 (CST) Received: from SZXEML450-HUB.china.huawei.com (10.82.67.193) by szxeml208-edg.china.huawei.com (172.24.2.57) with Microsoft SMTP Server (TLS) id 14.1.323.7; Tue, 28 May 2013 20:59:31 +0800 Received: from blrprnc09ns (10.18.96.98) by szxeml450-hub.china.huawei.com (10.82.67.193) with Microsoft SMTP Server id 14.1.323.7; Tue, 28 May 2013 20:59:30 +0800 From: Amit Kapila To: "=?iso-8859-1?Q?'Brice_Andr=E9'?=" CC: References: <51a458f5.6196420a.30dc.3d58SMTPIN_ADDED_BROKEN@mx.google.com> <005501ce5b7c$a9d56550$fd802ff0$@kapila@huawei.com> In-Reply-To: <005501ce5b7c$a9d56550$fd802ff0$@kapila@huawei.com> Subject: Re: bug in Prepared statement with DELETE RETURNING and rule on view Date: Tue, 28 May 2013 18:29:29 +0530 Message-ID: <008d01ce5ba3$31302a00$93907e00$@kapila@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Office Outlook 12.0 Thread-Index: Ac5beQ0kBnJccrefSryaDlEweiD2SwAA0xYgAAlhbhA= Content-Language: en-us X-Originating-IP: [10.18.96.98] X-CFilter-Loop: Reflected X-Pg-Spam-Score: -2.0 (--) 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, May 28, 2013 1:54 PM Brice Andr=E9 wrote: > On Tuesday, May 28, 2013 1:28 PM Brice Andr=E9 wrote: >=20 > I shall look into it today in later half of the day. > > Dear Amit, > > > > Thanks for your answer. > > > > I performed the same test as you and I get the same result (on my > > linux server, debian, postgresql 8.4). > > > > Maybe the problem is related to libpq ? > > > > Did you tried the C code provided to see if you can reproduce the > > problem ? I checked your C code and found the reason why you are not able to get the tuples returned by "Delete .. Returning .." Currently it is not supported to return tuples for non-select statements using PQexecPrepared and the reason is, there is no provision for Describe to send a RowDescription during this execution. You can refer function PortalRunMulti() in code, if you want to know more details. I could see below way for you to change your application if you want rows returned by "Delete .. Returning .." Use PQexec for below sql statements: prepare t1plan (int,int) AS Delete from v1 where c1 between $1 and $2 returning c1,deleted; Execute t1plan(10,90); After preparing once, you can call Execute SQL statement multiple times, it can save your time of prepare each time of delete statement, which was your motto for using PQexecPrepared(). > > > > > 2013/5/28 Amit Kapila : > > > On Tuesday, May 28, 2013 12:39 AM Brice Andr=E9 wrote: > > >> Dear all, > > >> > > >> I found what I really think is a bug in the postgresql 8.4. > > >> > > >> I have an sql database structure in which a real table has a > column > > >> that is used to mark the entries as deleted without really > deleting > > >> them. Then, I have a view that is hiding this to the users, with > > proper > > >> rules that perform real actions on the table. So, a ON DELETE rule > > on > > >> this view is performing an UPDATE which marks the rows as delete > > >> without deleting them. The view is hiding the rows tagged as > > deleted. > > >> > > >> This code is working from several years and I have a web-service > > that > > >> performs several actions on top of this database. Those actions > > include > > >> a "DELETE ... RETURNING ..." command on the view. This web-service > > was > > >> implemented by a php script that did not use any prepared > statement, > > >> and everything was working properly. > > >> > > >> I had performance issue with this solution and I decided to > rewrite > > the > > >> service in C++, and to use prepared statements. The SQL commands > are > > >> exactly the same, but they are now executed from a C++ application > > >> using libpq, and they use prepared statements. > > > > > > I had tried in latest 9.3 code with psql using prepared statements > > and it > > > worked fine, please see result below. > > > I shall check your libpq application code as well, but in the mean > > time can > > > you please verify whether the below works for you on 8.4 (I don't > > have 8.4 > > > setup). > > > > > > > > > postgres=3D> prepare t1plan (int,int) AS Delete from v1 where c1 > > between $1 > > > and $2 > > > returning c1,deleted; > > > PREPARE > > > postgres=3D> Execute t1plan(10,90); > > > c1 | deleted > > > ----+--------- > > > 10 | t > > > 11 | t > > > 12 | t > > > 13 | t > > > 14 | t > > > 15 | t > > > 16 | t > > > 17 | t > > > 18 | t > > > 19 | t > > > 20 | t > > > 21 | t > > > 22 | t > > > 23 | t > > > 24 | t > > > 25 | t > > > 26 | t > > > 27 | t > > > 28 | t > > > 29 | t > > > 30 | t > > > 31 | t > > > 32 | t > > > 33 | t > > > 34 | t > > > 35 | t > > > 36 | t > > > 37 | t > > > 38 | t > > > 39 | t > > > 40 | t > > > 41 | t > > > 42 | t > > > 43 | t > > > 44 | t > > > 45 | t > > > 46 | t > > > 47 | t > > > 48 | t > > > 49 | t > > > 50 | t > > > 51 | t > > > 52 | t > > > 53 | t > > > 54 | t > > > 55 | t > > > 56 | t > > > 57 | t > > > 58 | t > > > 59 | t > > > 60 | t > > > 61 | t > > > 62 | t > > > 63 | t > > > 64 | t > > > 65 | t > > > 66 | t > > > 67 | t > > > 68 | t > > > 69 | t > > > 70 | t > > > 71 | t > > > 72 | t > > > 73 | t > > > 74 | t > > > 75 | t > > > 76 | t > > > 77 | t > > > 78 | t > > > 79 | t > > > 80 | t > > > 81 | t > > > 82 | t > > > 83 | t > > > 84 | t > > > 85 | t > > > 86 | t > > > 87 | t > > > 88 | t > > > 89 | t > > > 90 | t > > > (81 rows) > > > > > > > > > DELETE 0 > > > > > > With Regards, > > > Amit Kapila. > > > >=20 >=20 >=20 > -- > Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-bugs --=20 Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs