Обсуждение: Cast Type

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

Cast Type

От
Thirumoorthy Bhuvneswari
Дата:
hi,
I am using Postgresql-7.1 on RedHat Linux-7.1. I would
like to know about cast types. I am having a tableA
with two fields cr_amt varchar(15) and dr_amt
varchar(15). I am having about 10000 records so I
could not recreate it. I am having tableB with cr_amt
float8 and dr_amt float8. I want to use 'sum' function
from the tableB.I gave the query as the follows:
'insert into tableB select
(cr_amt::float8),(dr_amt::float8) from tableA;'
It comes with the error,
'Cannot cast type 'varchar' to 'float8'. How could I
achieve this. Please help me. thanks.

regards,
T.Bhuvaneswari.

__________________________________________________
Do You Yahoo!?
Yahoo! Finance - Get real-time stock quotes
http://finance.yahoo.com

Re: Cast Type

От
"Peter Gibbs"
Дата:
Thirumoorthy Bhuvneswari wrote:

> I gave the query as the follows:
> 'insert into tableB select
> (cr_amt::float8),(dr_amt::float8) from tableA;'
> It comes with the error,
> 'Cannot cast type 'varchar' to 'float8'.

There is no function defined as converting directly from
varchar to float8. If you are going to be doing this a lot
you could create a conversion function, otherwise just do:

insert into tableB
  select cr_amt::text::float8, dr_amt::text::float8
  from tableA

--
Peter Gibbs
EmKel Systems