Re: How to copy data between joined columns? - Mailing list pgsql-sql

From Bryce Nesbitt
Subject Re: How to copy data between joined columns?
Date
Msg-id 4436E68D.6090207@obviously.com
Whole thread Raw
In response to Re: How to copy data between joined columns?  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-sql
Tom Lane wrote: <blockquote cite="mid17020.1144446846@sss.pgh.pa.us" type="cite"><pre wrap="">Bryce Nesbitt <a
class="moz-txt-link-rfc2396E"href="mailto:bryce1@obviously.com"><bryce1@obviously.com></a> writes:
</pre><blockquotetype="cite"><pre wrap="">If it were for the same rows in the same table, I would not have asked.
 
This is for columns from two tables, whos relationship is only
meaningful after a join.   </pre></blockquote><pre wrap="">
You have to write out the join condition longhand, eg

UPDATE targettable SET targcol = srccol
FROM srctable
WHERE joincol1 = joincol2;

This can be tricky, particularly if there might be more than one source
row joining to a given target row.  (IIRC, the effective behavior is
that any given target row's update will occur against a random one of
the possible join partners.)  A lot of people prefer to code it using
sub-selects. </pre></blockquote> That's great, and will work for me.  But I do have the multiple match issue.  Can you
alsogive a sub-select example for the archives?  Something robust that works against any combination of join partners
wouldbe really useful.<br /><br /><pre class="moz-signature" cols="60">-- 
 
----
Visit <a href="http://www.obviously.com/">http://www.obviously.com/</a>
</pre>

pgsql-sql by date:

Previous
From: Tom Lane
Date:
Subject: Re: How to copy data between joined columns?
Next
From: "Keith Hutchison"
Date:
Subject: Returning a set from an function