pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Combining output of several fields in SQL query
4+ messages / 2 participants
[nested] [flat]

* Combining output of several fields in SQL query
@ 2006-09-12 18:29 Allan Kamau <kamauallan@yahoo.com>
  2006-09-12 19:07 ` Re: Combining output of several fields in SQL query Aaron Bono <postgresql@aranya.com>
  0 siblings, 1 reply; 4+ messages in thread

From: Allan Kamau @ 2006-09-12 18:29 UTC (permalink / raw)
  To: pgsql-admin

Hi all,
This is a plain simple sql question appologies for
posting it here.

Am looking for a way of combining values from several
fields(and introducting value separators).

select field2+"_"+field1 from tableA;

I've tried 
select field2||'_'||field1 from tableA;
I get "1" as the result(which is not what I want).


Allan.

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 



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

* Re: Combining output of several fields in SQL query
  2006-09-12 18:29 Combining output of several fields in SQL query Allan Kamau <kamauallan@yahoo.com>
@ 2006-09-12 19:07 ` Aaron Bono <postgresql@aranya.com>
  2006-09-12 19:26   ` Re: Combining output of several fields in SQL query Allan Kamau <kamauallan@yahoo.com>
  0 siblings, 1 reply; 4+ messages in thread

From: Aaron Bono @ 2006-09-12 19:07 UTC (permalink / raw)
  To: Allan Kamau <kamauallan@yahoo.com>; +Cc: pgsql-admin

On 9/12/06, Allan Kamau <kamauallan@yahoo.com> wrote:
>
> Hi all,
> This is a plain simple sql question appologies for
> posting it here.
>
> Am looking for a way of combining values from several
> fields(and introducting value separators).
>
> select field2+"_"+field1 from tableA;
>
> I've tried
> select field2||'_'||field1 from tableA;
> I get "1" as the result(which is not what I want).



What does tableA look like (DDL and the data)?

==================================================================
   Aaron Bono
   Aranya Software Technologies, Inc.
   http://www.aranya.com
   http://codeelixir.com
==================================================================

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

* Re: Combining output of several fields in SQL query
  2006-09-12 18:29 Combining output of several fields in SQL query Allan Kamau <kamauallan@yahoo.com>
  2006-09-12 19:07 ` Re: Combining output of several fields in SQL query Aaron Bono <postgresql@aranya.com>
@ 2006-09-12 19:26   ` Allan Kamau <kamauallan@yahoo.com>
  2006-09-12 20:08     ` Re: Combining output of several fields in SQL query Aaron Bono <postgresql@aranya.com>
  0 siblings, 1 reply; 4+ messages in thread

From: Allan Kamau @ 2006-09-12 19:26 UTC (permalink / raw)
  To: Aaron Bono <postgresql@aranya.com>; +Cc: pgsql-admin

create table tableA(
s_l_p_p_v_i text not null,
field1 text not null,
field2 text not null,
primary key(field1,field2));

s_l_p_p_v_i field1 field1
abc         2      1
xyz         2      4
klm         2      3




--- Aaron Bono <postgresql@aranya.com> wrote:

> On 9/12/06, Allan Kamau <kamauallan@yahoo.com>
> wrote:
> >
> > Hi all,
> > This is a plain simple sql question appologies for
> > posting it here.
> >
> > Am looking for a way of combining values from
> several
> > fields(and introducting value separators).
> >
> > select field2+"_"+field1 from tableA;
> >
> > I've tried
> > select field2||'_'||field1 from tableA;
> > I get "1" as the result(which is not what I want).
> 
> 
> 
> What does tableA look like (DDL and the data)?
> 
>
==================================================================
>    Aaron Bono
>    Aranya Software Technologies, Inc.
>    http://www.aranya.com
>    http://codeelixir.com
>
==================================================================
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 



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

* Re: Combining output of several fields in SQL query
  2006-09-12 18:29 Combining output of several fields in SQL query Allan Kamau <kamauallan@yahoo.com>
  2006-09-12 19:07 ` Re: Combining output of several fields in SQL query Aaron Bono <postgresql@aranya.com>
  2006-09-12 19:26   ` Re: Combining output of several fields in SQL query Allan Kamau <kamauallan@yahoo.com>
@ 2006-09-12 20:08     ` Aaron Bono <postgresql@aranya.com>
  0 siblings, 0 replies; 4+ messages in thread

From: Aaron Bono @ 2006-09-12 20:08 UTC (permalink / raw)
  To: Allan Kamau <kamauallan@yahoo.com>; +Cc: pgsql-admin

On 9/12/06, Allan Kamau <kamauallan@yahoo.com> wrote:
>
> create table tableA(
> s_l_p_p_v_i text not null,
> field1 text not null,
> field2 text not null,
> primary key(field1,field2));
>
> s_l_p_p_v_i field1 field1
> abc         2      1
> xyz         2      4
> klm         2      3


Your initial query:

select field2||'_'||field1 from tableA;

works perfectly for me:

?column?
4_2
1_2
3_2

Are you sure you are not getting the correct results?

==================================================================
   Aaron Bono
   Aranya Software Technologies, Inc.
   http://www.aranya.com
   http://codeelixir.com
==================================================================

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


end of thread, other threads:[~2006-09-12 20:08 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-09-12 18:29 Combining output of several fields in SQL query Allan Kamau <kamauallan@yahoo.com>
2006-09-12 19:07 ` Aaron Bono <postgresql@aranya.com>
2006-09-12 19:26   ` Allan Kamau <kamauallan@yahoo.com>
2006-09-12 20:08     ` Aaron Bono <postgresql@aranya.com>

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