Non-procedural field merging?

From: "Richard Huxton" <dev(at)archonet(dot)com>
To: <pgsql-sql(at)postgresql(dot)org>
Subject: Non-procedural field merging?
Date: 2001-01-05 09:59:20
Message-ID: 000f01c076fe$2e27b9a0$1001a8c0@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

I have two tables, foo and foo2:

richardh=> select * from foo;
a | b
---+-----
1 | xxx
1 | 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

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message rob 2001-01-05 13:24:34 Re: Casting
Previous Message Marc Cromme 2001-01-05 08:46:58 Extracting user db tabel info from system tables???