pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-hackers@postgreSQL.org
Subject: Bogus use of *-expansion in UPDATE
Date: Sat, 19 Nov 2016 17:42:10 -0500
Message-ID: <4308.1479595330@sss.pgh.pa.us> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>

You get an odd result if you write "something.*" in an UPDATE's
source expressions:

regression=# create table t1 (f1 int, f2 int, f3 int);
CREATE TABLE
regression=# update t1 set f1 = t1.*;
ERROR:  UPDATE target count mismatch --- internal error

The reason for that is that we use transformTargetList() to do
parse analysis of the source expressions, and it thinks it should
expand "t1.*" into "t1.f1, t1.f2, t1.f3" as we would do in a SELECT.
This seems nonsensical to me: there is no way that there can be
more than one source expression for a given target column.

It would make sense to do *-expansion in this context:

regression=# update t1 set (f1,f2,f3) = (t1.*);

since that's implicitly a row constructor and we're supposed to do
*-expansion in row constructors.  Currently it doesn't work:

ERROR:  number of columns does not match number of values
LINE 1: update t1 set (f1,f2,f3) = (t1.*);
                                   ^

which I think is a separate bug, or at least missing feature, in the
multi-target-column feature.  It would take a little work to fix
that, since the expansion would have to wait till parse analysis,
whereas currently we separate the column targets in gram.y.

In short, I think we should modify transformTargetList so that it
doesn't do *-expansion when processing a simple UPDATE SET expression.
I'm not sufficiently motivated to rewrite the code enough to fix the
second case right now, but the first case seems like a simple
bug fix.  I would expect

	UPDATE tab SET composite_column = foo.*

to be capable of working, but right now it's busted.

			regards, tom lane


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



Message-ID: <4308.1479595330@sss.pgh.pa.us>
Permalink:  ../4308.1479595330@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/4308.1479595330@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-hackers@postgresql.org
  Cc: tgl@sss.pgh.pa.us
  Subject: Re: Bogus use of *-expansion in UPDATE
  In-Reply-To: <4308.1479595330@sss.pgh.pa.us>
  References: <4308.1479595330@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