pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Amit Kapila <amit.kapila@huawei.com>
Cc: 'Brice André' <brice@famille-andre.be>
Cc: pgsql-bugs@postgresql.org
Subject: Re: bug in Prepared statement with DELETE RETURNING and rule on view
Date: Mon, 10 Jun 2013 14:45:26 -0400
Message-ID: <27432.1370889926@sss.pgh.pa.us> (raw)
In-Reply-To: <00b101ce5bb3$840448f0$8c0cdad0$@kapila@huawei.com>
References: <CAOBG12n-8X96_HM+zwwSYZmUoR1tsOrxqsZZPyhRSKL0j4p2ng@mail.gmail.com>
	<51a458f5.6196420a.30dc.3d58SMTPIN_ADDED_BROKEN@mx.google.com>
	<CAOBG12k4QWzhA7DPH9BFCaTVp+YTBO4+FzYCRkcWUkmKTQtHvA@mail.gmail.com>
	<51a4aae6.cade440a.44ca.ffff81a1SMTPIN_ADDED_BROKEN@mx.google.com>
	<CAOBG12ntUc3FMO5_bf9wXwPs7SyiXA5JYe+h7Y5qZNT3auSweA@mail.gmail.com>
	<00b101ce5bb3$840448f0$8c0cdad0$@kapila@huawei.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

[ got around to looking at this thread finally ]

Amit Kapila <amit.kapila@huawei.com> 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.

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.

			regards, tom lane


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



view thread (8+ messages)  latest in thread

Message-ID: <27432.1370889926@sss.pgh.pa.us>
Permalink:  ../27432.1370889926@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/27432.1370889926@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, amit.kapila@huawei.com, brice@famille-andre.be
  Subject: Re: bug in Prepared statement with DELETE RETURNING and rule on view
  In-Reply-To: <27432.1370889926@sss.pgh.pa.us>
  References: <CAOBG12n-8X96_HM+zwwSYZmUoR1tsOrxqsZZPyhRSKL0j4p2ng@mail.gmail.com> <51a458f5.6196420a.30dc.3d58SMTPIN_ADDED_BROKEN@mx.google.com> <CAOBG12k4QWzhA7DPH9BFCaTVp+YTBO4+FzYCRkcWUkmKTQtHvA@mail.gmail.com> <51a4aae6.cade440a.44ca.ffff81a1SMTPIN_ADDED_BROKEN@mx.google.com> <CAOBG12ntUc3FMO5_bf9wXwPs7SyiXA5JYe+h7Y5qZNT3auSweA@mail.gmail.com> <00b101ce5bb3$840448f0$8c0cdad0$@kapila@huawei.com> <27432.1370889926@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox