Обсуждение: concatenate 2 numeric columns..

Поиск
Список
Период
Сортировка

concatenate 2 numeric columns..

От
Anand Raman
Дата:
hi guys
I wish to concatenate 2 columns of numeric type.. How can it be done..


Earlier i tried using the to_char function but it seems to be crashing
the backend. Any other option will be greatly appreciated..


select to_char(length,'9999D99') || to_char(breadth,'9999D99') from exhibit_distributions

This query seems to be crashing the backend when executed over the
table..  However when constrained using a appropriate where clause it
works..

Any other approach??.

Thanx
Anand


Re: concatenate 2 numeric columns..

От
Bruno Wolff III
Дата:
I saw some similar things when using to_char on columns will null
values. I used a case statement to check for nulls in 7.0.3. When
I switched to using 7.1beta3, the problem was fixed.

On Thu, Jan 25, 2001 at 01:42:44AM +0530,
  Anand Raman <araman@india-today.com> wrote:
> hi guys
> I wish to concatenate 2 columns of numeric type.. How can it be done..
>
>
> Earlier i tried using the to_char function but it seems to be crashing
> the backend. Any other option will be greatly appreciated..
>
>
> select to_char(length,'9999D99') || to_char(breadth,'9999D99') from exhibit_distributions
>
> This query seems to be crashing the backend when executed over the
> table..  However when constrained using a appropriate where clause it
> works..
>
> Any other approach??.
>
> Thanx
> Anand
>

Re: concatenate 2 numeric columns..

От
"Rob Arnold"
Дата:
The coalesce function can help with nulls.  It takes a list of attributes or
literals and returns the first non-null value.

I use it like this:

select coalesce(numeric_attrib, 0) from some_table;

--rob

----- Original Message -----
From: "Bruno Wolff III" <bruno@wolff.to>
To: "postgresql" <pgsql-general@postgresql.org>
Sent: Wednesday, January 24, 2001 7:49 PM
Subject: Re: concatenate 2 numeric columns..


> I saw some similar things when using to_char on columns will null
> values. I used a case statement to check for nulls in 7.0.3. When
> I switched to using 7.1beta3, the problem was fixed.
>
> On Thu, Jan 25, 2001 at 01:42:44AM +0530,
>   Anand Raman <araman@india-today.com> wrote:
> > hi guys
> > I wish to concatenate 2 columns of numeric type.. How can it be done..
> >
> >
> > Earlier i tried using the to_char function but it seems to be crashing
> > the backend. Any other option will be greatly appreciated..
> >
> >
> > select to_char(length,'9999D99') || to_char(breadth,'9999D99') from
exhibit_distributions
> >
> > This query seems to be crashing the backend when executed over the
> > table..  However when constrained using a appropriate where clause it
> > works..
> >
> > Any other approach??.
> >
> > Thanx
> > Anand
> >
>


Re: Re: concatenate 2 numeric columns..

От
Guy Fraser
Дата:
Bruno Wolff III wrote:
>
> I saw some similar things when using to_char on columns will null
> values. I used a case statement to check for nulls in 7.0.3. When
> I switched to using 7.1beta3, the problem was fixed.
>
> On Thu, Jan 25, 2001 at 01:42:44AM +0530,
>   Anand Raman <araman@india-today.com> wrote:
> > hi guys
> > I wish to concatenate 2 columns of numeric type.. How can it be done..
> >
> >
> > Earlier i tried using the to_char function but it seems to be crashing
> > the backend. Any other option will be greatly appreciated..
> >
> >
> > select to_char(length,'9999D99') || to_char(breadth,'9999D99') from exhibit_distributions
> >
> > This query seems to be crashing the backend when executed over the
> > table..  However when constrained using a appropriate where clause it
> > works..
> >
> > Any other approach??.
> >
> > Thanx
> > Anand
> >

Hi

I am using 7.0.2, here is and example.

Acct-Session-Time is int4
Acct-Delay-Time   is int4


select "Acct-Session-Time" || ',' || "Acct-Delay-Time" as
compound_numbers from febstop limit 2;
compound_numbers
-----------------
1137,0
2083,0
(2 rows)

I also tried :

select "Acct-Session-Time"::text || ',' || "Acct-Delay-Time"::text as
compound_numbers from febstop limit 2;
compound_numbers
-----------------
1137,0
2083,0
(2 rows)

This is pretty simple but it works for me.

Guy