From: Ben Kim <bkim@tamu.edu>
To: giuseppe.derossi@email.it
Cc: pgsql-admin@postgresql.org
Subject: Re: merge two rows where value are null
Date: Tue, 14 Aug 2007 08:34:02 -0500 (CDT)
Message-ID: <Pine.GSO.4.64.0708140820250.8353@coe.tamu.edu> (raw)
In-Reply-To: <2fbf3fefb2389d08d2aedf3b60d85557@83.225.63.234>
References: <2fbf3fefb2389d08d2aedf3b60d85557@83.225.63.234>
On Tue, 14 Aug 2007, giuseppe.derossi@email.it wrote:
> Name, Surname , Job, Hobby, Pet, address
> John, Smith, NULL, photo, NULL, NULL
> John, Smith, student, NULL, cat, NULL
> by using name and surname as selecting key, I want :
>
> John, Smith, student, photo, cat, NULL
If you are sure there's no conflict (multiple values) for a (name,
surname) key, one simple solution might be (surely not an efficient one)
select
(select distinct Name from thetable where Name = 'name1' and Surname = 'surname1' where Name is not null),
(select distinct Surname from thetable where Name = 'name1' and Surname = 'surname1' where Surname is not null),
(select distinct Job from thetable where Name = 'name1' and Surname = 'surname1' where Job is not null),
(select distinct Hobby from thetable where Name = 'name1' and Surname = 'surname1' where Hobby is not null),
(select distinct Pet from thetable where Name = 'name1' and Surname = 'surname1' where Pet is not null),
(select distinct address from thetable where Name = 'name1' and Surname = 'surname1' where address is not null)
This will fail if you also have
John, Smith, student, NULL, dog, NULL
in addition to
> John, Smith, student, NULL, cat, NULL
You can test for offending rows by:
select
array_to_string( array( select distinct Pet from thetable where Name = 'name1' and Surname = 'surname1' where Pet is not null),',')
and so on...
Regards,
Ben K.
Developer
http://benix.tamu.edu
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-admin@postgresql.org
Cc: bkim@tamu.edu, giuseppe.derossi@email.it
Subject: Re: merge two rows where value are null
In-Reply-To: <Pine.GSO.4.64.0708140820250.8353@coe.tamu.edu>
References: <2fbf3fefb2389d08d2aedf3b60d85557@83.225.63.234> <Pine.GSO.4.64.0708140820250.8353@coe.tamu.edu>
* 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