Re: UPDATE SET (a,b,c) = (SELECT ...) versus rules

Martijn van Oosterhout <kleptog@svana.org>

From: Martijn van Oosterhout <kleptog@svana.org>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-hackers@postgreSQL.org
Date: 2014-06-17T07:18:18Z
Lists: pgsql-hackers
On Sat, Jun 14, 2014 at 03:35:33PM -0400, Tom Lane wrote:
> The best that I think is reasonable to do in such cases is to pull out
> a separate copy of the sub-select for each actual NEW reference in a
> rule query.  So the example above would give rise to an expanded
> rule query along the lines of
> 
> 	INSERT INTO foolog VALUES ( (SELECT x as a, y as b, ...).a,
> 	                            (SELECT x as a, y as b, ...).b,
> 	                            ... );

Would it not be possible to use WITH here, like:

WITH bar AS ( ... subselect ... )
INSERT INTO foolog VALUES (bar.a, bar.b, ...)

Or am I missing something?

Have a nice day,
-- 
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> He who writes carelessly confesses thereby at the very outset that he does
> not attach much importance to his own thoughts.
   -- Arthur Schopenhauer