pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Add one column to another
7+ messages / 7 participants
[nested] [flat]

* Add one column to another
@ 2011-08-25 14:21 gvim <gvimrc@gmail.com>
  2011-08-25 14:30 ` Re: Add one column to another Tony Capobianco <tcapobianco@prospectiv.com>
  2011-08-25 14:52 ` Re: Add one column to another Oliveiros d'Azevedo Cristina <oliveiros.cristina@marktest.pt>
  2011-08-25 14:53 ` Re: Add one column to another David Johnston <polobo@yahoo.com>
  2011-08-25 17:50 ` Re: Add one column to another Tim Landscheidt <tim@tim-landscheidt.de>
  0 siblings, 4 replies; 7+ messages in thread

From: gvim @ 2011-08-25 14:21 UTC (permalink / raw)
  To: pgsql-sql

I have to deal with a table which contains:

first_name
surname
email1
email2

... and I would like to create a view which combines both email columns thus:

first_name
surname
email

It looks simple but I can't think of an obvious query.

gvim



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Add one column to another
  2011-08-25 14:21 Add one column to another gvim <gvimrc@gmail.com>
@ 2011-08-25 14:30 ` Tony Capobianco <tcapobianco@prospectiv.com>
  3 siblings, 0 replies; 7+ messages in thread

From: Tony Capobianco @ 2011-08-25 14:30 UTC (permalink / raw)
  To: gvim <gvimrc@gmail.com>; +Cc: pgsql-sql

Use the concat || operator.


On Thu, 2011-08-25 at 15:21 +0100, gvim wrote:
> I have to deal with a table which contains:
> 
> first_name
> surname
> email1
> email2
> 
> ... and I would like to create a view which combines both email columns thus:
> 
> first_name
> surname
> email
> 
> It looks simple but I can't think of an obvious query.
> 
> gvim
> 





^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Add one column to another
  2011-08-25 14:21 Add one column to another gvim <gvimrc@gmail.com>
@ 2011-08-25 14:52 ` Oliveiros d'Azevedo Cristina <oliveiros.cristina@marktest.pt>
  2011-08-25 17:54   ` Re: Add one column to another Scott Marlowe <scott.marlowe@gmail.com>
  3 siblings, 1 reply; 7+ messages in thread

From: Oliveiros d'Azevedo Cristina @ 2011-08-25 14:52 UTC (permalink / raw)
  To: gvim <gvimrc@gmail.com>; pgsql-sql

Something like this...?

SELECT first_name,surname, email1 || ';' || email2
FROM t_your_table;


Best,
Oliver

----- Original Message ----- 
From: "gvim" <gvimrc@gmail.com>
To: "pgsql sql" <pgsql-sql@postgresql.org>
Sent: Thursday, August 25, 2011 3:21 PM
Subject: [SQL] Add one column to another


>I have to deal with a table which contains:
>
> first_name
> surname
> email1
> email2
>
> ... and I would like to create a view which combines both email columns 
> thus:
>
> first_name
> surname
> email
>
> It looks simple but I can't think of an obvious query.
>
> gvim
>
> -- 
> Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql 




^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Add one column to another
  2011-08-25 14:21 Add one column to another gvim <gvimrc@gmail.com>
  2011-08-25 14:52 ` Re: Add one column to another Oliveiros d'Azevedo Cristina <oliveiros.cristina@marktest.pt>
@ 2011-08-25 17:54   ` Scott Marlowe <scott.marlowe@gmail.com>
  2011-08-25 19:46     ` Re: Add one column to another vipul shah <vipmshah@gmail.com>
  0 siblings, 1 reply; 7+ messages in thread

From: Scott Marlowe @ 2011-08-25 17:54 UTC (permalink / raw)
  To: Oliveiros d'Azevedo Cristina <oliveiros.cristina@marktest.pt>; +Cc: gvim <gvimrc@gmail.com>; pgsql-sql

On Thu, Aug 25, 2011 at 8:52 AM, Oliveiros d'Azevedo Cristina
<oliveiros.cristina@marktest.pt> wrote:
> Something like this...?
>
> SELECT first_name,surname, email1 || ';' || email2
> FROM t_your_table;

If there's any nulls in email1 or email2 they'll need special handling
with coalesce.



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Add one column to another
  2011-08-25 14:21 Add one column to another gvim <gvimrc@gmail.com>
  2011-08-25 14:52 ` Re: Add one column to another Oliveiros d'Azevedo Cristina <oliveiros.cristina@marktest.pt>
  2011-08-25 17:54   ` Re: Add one column to another Scott Marlowe <scott.marlowe@gmail.com>
@ 2011-08-25 19:46     ` vipul shah <vipmshah@gmail.com>
  0 siblings, 0 replies; 7+ messages in thread

From: vipul shah @ 2011-08-25 19:46 UTC (permalink / raw)
  To: Scott Marlowe <scott.marlowe@gmail.com>; +Cc: Oliveiros d'Azevedo Cristina <oliveiros.cristina@marktest.pt>; gvim <gvimrc@gmail.com>; pgsql-sql

Check this link.

It's useful to resolve the issue.

http://blog.ropardo.ro/2010/05/04/extending-postgresql-a-better-concat-operator/

- Vipul


On Thu, Aug 25, 2011 at 12:54 PM, Scott Marlowe <scott.marlowe@gmail.com>wrote:

> On Thu, Aug 25, 2011 at 8:52 AM, Oliveiros d'Azevedo Cristina
> <oliveiros.cristina@marktest.pt> wrote:
> > Something like this...?
> >
> > SELECT first_name,surname, email1 || ';' || email2
> > FROM t_your_table;
>
> If there's any nulls in email1 or email2 they'll need special handling
> with coalesce.
>
> --
> Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql
>

^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Add one column to another
  2011-08-25 14:21 Add one column to another gvim <gvimrc@gmail.com>
@ 2011-08-25 14:53 ` David Johnston <polobo@yahoo.com>
  3 siblings, 0 replies; 7+ messages in thread

From: David Johnston @ 2011-08-25 14:53 UTC (permalink / raw)
  To: 'gvim' <gvimrc@gmail.com>; pgsql-sql

I have to deal with a table which contains:

first_name
surname
email1
email2

... and I would like to create a view which combines both email columns
thus:

first_name
surname
email

It looks simple but I can't think of an obvious query.

-----------------------------------------------------------

SELECT first_name, surname, ARRAY[email1, email2] AS email
FROM [...]

David J.




^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Add one column to another
  2011-08-25 14:21 Add one column to another gvim <gvimrc@gmail.com>
@ 2011-08-25 17:50 ` Tim Landscheidt <tim@tim-landscheidt.de>
  3 siblings, 0 replies; 7+ messages in thread

From: Tim Landscheidt @ 2011-08-25 17:50 UTC (permalink / raw)
  To: pgsql-sql

(anonymous) wrote:

> I have to deal with a table which contains:

> first_name
> surname
> email1
> email2

> ... and I would like to create a view which combines both email columns thus:

> first_name
> surname
> email

> It looks simple but I can't think of an obvious query.

Try:

| SELECT first_name, surname, email1 AS email FROM testtable WHERE email1 IS NOT NULL UNION ALL
| SELECT first_name, surname, email2 AS email FROM testtable WHERE email2 IS NOT NULL;

Tim




^ permalink  raw  reply  [nested|flat] 7+ messages in thread


end of thread, other threads:[~2011-08-25 19:46 UTC | newest]

Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2011-08-25 14:21 Add one column to another gvim <gvimrc@gmail.com>
2011-08-25 14:30 ` Tony Capobianco <tcapobianco@prospectiv.com>
2011-08-25 14:52 ` Oliveiros d'Azevedo Cristina <oliveiros.cristina@marktest.pt>
2011-08-25 17:54   ` Scott Marlowe <scott.marlowe@gmail.com>
2011-08-25 19:46     ` vipul shah <vipmshah@gmail.com>
2011-08-25 14:53 ` David Johnston <polobo@yahoo.com>
2011-08-25 17:50 ` Tim Landscheidt <tim@tim-landscheidt.de>

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