Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UhE5n-0004VP-RA for pgsql-bugs@arkaria.postgresql.org; Tue, 28 May 2013 07:13:12 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1UhE5n-0002XV-2j for pgsql-bugs@arkaria.postgresql.org; Tue, 28 May 2013 07:13:11 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UhE5m-0002XP-3z for pgsql-bugs@postgresql.org; Tue, 28 May 2013 07:13:10 +0000 Received: from szxga01-in.huawei.com ([119.145.14.64]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1UhE5b-0002ma-9v for pgsql-bugs@postgresql.org; Tue, 28 May 2013 07:13:09 +0000 Received: from 172.24.2.119 (EHLO szxeml210-edg.china.huawei.com) ([172.24.2.119]) by szxrg01-dlp.huawei.com (MOS 4.3.4-GA FastPath queued) with ESMTP id BCV01005; Tue, 28 May 2013 15:12:47 +0800 (CST) Received: from SZXEML402-HUB.china.huawei.com (10.82.67.32) by szxeml210-edg.china.huawei.com (172.24.2.183) with Microsoft SMTP Server (TLS) id 14.1.323.7; Tue, 28 May 2013 15:11:24 +0800 Received: from blrprnc09ns (10.18.96.98) by szxeml402-hub.china.huawei.com (10.82.67.32) with Microsoft SMTP Server id 14.1.323.7; Tue, 28 May 2013 15:11:24 +0800 From: Amit Kapila To: "=?iso-8859-1?Q?'Brice_Andr=E9'?=" , References: In-Reply-To: Subject: Re: bug in Prepared statement with DELETE RETURNING and rule on view Date: Tue, 28 May 2013 12:41:22 +0530 Message-ID: <005101ce5b72$903b5550$b0b1fff0$@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: Ac5bDb+/35slHtMYTGq3C3qpBtl8NAAY/vmw Content-Language: en-us X-Originating-IP: [10.18.96.98] X-CFilter-Loop: Reflected X-Pg-Spam-Score: 0.7 (/) 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 12:39 AM Brice Andr=E9 wrote: > Dear all, >=20 > I found what I really think is a bug in the postgresql 8.4. >=20 > 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. >=20 > 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. >=20 > 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=20 returning c1,deleted;=20 PREPARE=20 postgres=3D> Execute t1plan(10,90);=20 c1 | deleted=20 ----+---------=20 10 | t=20 11 | t=20 12 | t=20 13 | t=20 14 | t=20 15 | t=20 16 | t=20 17 | t=20 18 | t=20 19 | t=20 20 | t=20 21 | t=20 22 | t=20 23 | t=20 24 | t=20 25 | t=20 26 | t=20 27 | t=20 28 | t=20 29 | t=20 30 | t=20 31 | t=20 32 | t=20 33 | t=20 34 | t=20 35 | t=20 36 | t=20 37 | t=20 38 | t=20 39 | t=20 40 | t=20 41 | t=20 42 | t=20 43 | t=20 44 | t=20 45 | t=20 46 | t=20 47 | t=20 48 | t=20 49 | t=20 50 | t=20 51 | t=20 52 | t=20 53 | t=20 54 | t=20 55 | t=20 56 | t=20 57 | t=20 58 | t=20 59 | t=20 60 | t=20 61 | t=20 62 | t=20 63 | t=20 64 | t=20 65 | t=20 66 | t=20 67 | t=20 68 | t=20 69 | t=20 70 | t=20 71 | t=20 72 | t=20 73 | t=20 74 | t=20 75 | t=20 76 | t=20 77 | t=20 78 | t=20 79 | t=20 80 | t=20 81 | t=20 82 | t=20 83 | t=20 84 | t=20 85 | t=20 86 | t=20 87 | t=20 88 | t=20 89 | t=20 90 | t=20 (81 rows)=20 DELETE 0=20 With Regards, Amit Kapila. --=20 Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs