pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andrew Gierth <andrew@tao11.riddles.org.uk>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: 110876189@qq.com
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #15237: I got "ERROR: source for a multiple-column UPDATE item must be a sub-SELECT or ROW() expression"
Date: Tue, 12 Jun 2018 12:40:02 +0100
Message-ID: <87muw0tfml.fsf@news-spur.riddles.org.uk> (raw)
In-Reply-To: <87r2lctidw.fsf@news-spur.riddles.org.uk>
References: <152876885706.32361.1270737678956483321@wrigleys.postgresql.org>
	<22079.1528774703@sss.pgh.pa.us>
	<87r2lctidw.fsf@news-spur.riddles.org.uk>

>>>>> "Andrew" == Andrew Gierth <andrew@tao11.riddles.org.uk> writes:

>>>>> "Tom" == Tom Lane <tgl@sss.pgh.pa.us> writes:

 >>> On PostgreSQL 11 Beta, I exec sql like "update
 >>> fvt_obj_operate_update_table_033 set (c_int) = (20) where c_int = 20;",
 >>> which only on column to set, got ""ERROR:  source for a multiple-column
 >>> UPDATE item must be a sub-SELECT or ROW() expression"".

 Tom> It's telling you what to do: use a ROW() expression, ie

 Tom> update fvt_obj_operate_update_table_033 set (c_int) = row(20)
 Tom> where c_int = 20;

 Andrew> Yeah, but (a) this used to work, and has worked since at least
 Andrew> as far back as 9.0, and (b) the spec requires it to work.

Looking at the previous discussion, in fact, it seems that you were
under the misapprehension that the spec requires the use of ROW there;
it does not. So this is actually broken in pg 10.

Here is the expansion with references according to sql2016 (leaving out
all the irrelevant bits):

14.15 <set clause list>

<multiple column assignment> ::=
   <set target list> <equals operator> <assigned row>

<assigned row> ::=
   <contextually typed row value expression>

7.2 <row value expression>

<contextually typed row value expression> ::=
    <contextually typed row value constructor>

7.1 <row value constructor>

<contextually typed row value constructor> ::=
       <common value expression>

6.28 <value expression>

<common value expression> ::=
       <numeric value expression>

<numeric value expression> ::= [snipped for brevity]

<numeric primary> ::=
       <value expression primary>

6.3 <value expression primary>

<value expression primary> ::=
       <parenthesized value expression>

(I'll stop here since (20) is obviously a <parenthesized value expression>)

At this point, we go back up the stack to 7.1 <row value constructor>,
where we find this syntax rule:

5) Let CTRVC be the <contextually typed row value constructor>.
   a) If CTRVC is a <common value expression>, <boolean value expression>,
      or <contextually typed value specification> X, then CTRVC is
      equivalent to:

         ROW ( X )

So by the time we get back to syntax rule 4 of 14.15 <set clause list>,
the <assigned row> term is not (20) but ROW( (20) ), and the expansion
into individual columns succeeds.

Another obvious way to see that ROW isn't required here by the spec is
to notice that INSERT ... VALUES (20); also doesn't need ROW, and that's
using the same syntax (specifically, <contextually typed row
value constructor> is used in both cases).

-- 
Andrew (irc:RhodiumToad)




view thread (12+ messages)  latest in thread

Message-ID: <87muw0tfml.fsf@news-spur.riddles.org.uk>
Permalink:  ../87muw0tfml.fsf@news-spur.riddles.org.uk/
Also on:    postgresql.org/message-id/87muw0tfml.fsf@news-spur.riddles.org.uk

 · 

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: andrew@tao11.riddles.org.uk, tgl@sss.pgh.pa.us, 110876189@qq.com
  Subject: Re: BUG #15237: I got "ERROR: source for a multiple-column UPDATE item must be a sub-SELECT or ROW() expression"
  In-Reply-To: <87muw0tfml.fsf@news-spur.riddles.org.uk>
  References: <152876885706.32361.1270737678956483321@wrigleys.postgresql.org> <22079.1528774703@sss.pgh.pa.us> <87r2lctidw.fsf@news-spur.riddles.org.uk> <87muw0tfml.fsf@news-spur.riddles.org.uk>

* 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