pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Richard Huxton <dev@archonet.com>
To: pgsql-sql@postgresql.org
Subject: Non-procedural field merging?
Date: Fri, 5 Jan 2001 09:59:20 -0000
Message-ID: <000f01c076fe$2e27b9a0$1001a8c0@archonet.com> (raw)

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




view thread (3+ messages)  latest in thread

Message-ID: <000f01c076fe$2e27b9a0$1001a8c0@archonet.com>
Permalink:  ../000f01c076fe$2e27b9a0$1001a8c0@archonet.com/
Also on:    postgresql.org/message-id/000f01c076fe$2e27b9a0$1001a8c0@archonet.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: dev@archonet.com
  Subject: Re: Non-procedural field merging?
  In-Reply-To: <000f01c076fe$2e27b9a0$1001a8c0@archonet.com>
  References: <000f01c076fe$2e27b9a0$1001a8c0@archonet.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox