Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fShen-0003Dr-Pp for pgsql-bugs@arkaria.postgresql.org; Tue, 12 Jun 2018 11:40:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fShel-0006LM-Ux for pgsql-bugs@arkaria.postgresql.org; Tue, 12 Jun 2018 11:40:11 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fShel-0006L8-P7 for pgsql-bugs@lists.postgresql.org; Tue, 12 Jun 2018 11:40:11 +0000 Received: from lungold.riddles.org.uk ([82.68.208.19]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fShei-0000fn-IG for pgsql-bugs@lists.postgresql.org; Tue, 12 Jun 2018 11:40:11 +0000 Received: from [192.168.127.1] (port=41764 helo=caithnard.riddles.org.uk) by lungold.riddles.org.uk with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.88 (FreeBSD)) (envelope-from ) id 1fShed-000KG9-Mn; Tue, 12 Jun 2018 11:40:03 +0000 Received: from [127.0.0.1] (port=32650 helo=caithnard.riddles.org.uk) by caithnard.riddles.org.uk with esmtp (Exim 4.89 (FreeBSD)) (envelope-from ) id 1fShed-000Lx2-0a; Tue, 12 Jun 2018 11:40:03 +0000 From: Andrew Gierth To: Tom Lane Cc: 110876189@qq.com, 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" In-Reply-To: <87r2lctidw.fsf@news-spur.riddles.org.uk> (Andrew Gierth's message of "Tue, 12 Jun 2018 11:28:38 +0100") Message-ID: <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> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (berkeley-unix) Date: Tue, 12 Jun 2018 12:40:02 +0100 MIME-Version: 1.0 Content-Type: text/plain List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk >>>>> "Andrew" == Andrew Gierth writes: >>>>> "Tom" == Tom Lane 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 ::= ::= 7.2 ::= 7.1 ::= 6.28 ::= ::= [snipped for brevity] ::= 6.3 ::= (I'll stop here since (20) is obviously a ) At this point, we go back up the stack to 7.1 , where we find this syntax rule: 5) Let CTRVC be the . a) If CTRVC is a , , or X, then CTRVC is equivalent to: ROW ( X ) So by the time we get back to syntax rule 4 of 14.15 , the 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, is used in both cases). -- Andrew (irc:RhodiumToad)