Non-procedural field merging? - Mailing list pgsql-sql

From Richard Huxton
Subject Non-procedural field merging?
Date
Msg-id 000f01c076fe$2e27b9a0$1001a8c0@archonet.com
Whole thread Raw
Responses Re: Non-procedural field merging?  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-sql
I have two tables, foo and foo2:

richardh=> select * from foo;a |  b
---+-----1 | xxx1 | yyy

richardh=> select * from foo2;c | d
---+---1 |

And I would like to set d to 'xxxyyy' (i.e. merge entries from b). Of course
the following doesn't work because the 'd' seen is the one from before the
query starts.

richardh=> update foo2 set d = d || foo.b from foo where foo.a=foo2.c;
UPDATE 1
richardh=> select * from foo2;c |  d
---+-----1 | yyy

Now - I can always solve the problem procedurally, merging the values in my
application but I was wondering if any of the smarter people on the list
have an SQL way of doing it (something with sub-queries?)

PS - I realise I might get 'xxxyyy' or 'yyyxxx' without forcing an order but
I don't actually care in this case.

TIA

- Richard Huxton



pgsql-sql by date:

Previous
From: Marc Cromme
Date:
Subject: Extracting user db tabel info from system tables???
Next
From: Tom Lane
Date:
Subject: Re: Non-procedural field merging?