Re: Type conversion from TEXT to DOUBLE PRECISION

From: Daniel Lau <iedaniel(at)ust(dot)hk>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Richard Huxton <dev(at)archonet(dot)com>, pgsql-sql(at)postgresql(dot)org, Karel Zak <zakkr(at)zf(dot)jcu(dot)cz>
Subject: Re: Type conversion from TEXT to DOUBLE PRECISION
Date: 2004-01-09 15:44:36
Message-ID: Pine.GSO.3.95L.1040109233321.6593B-100000@uststf1
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


On Fri, 9 Jan 2004, Tom Lane wrote:

> Richard Huxton <dev(at)archonet(dot)com> writes:
> > Since your error seems to be complaining about a space, I'd guess you've got
> > other than numeric values in _aaa.
>
> In fact, with a bit of experimentation I see the same error message:
>
> regression=# select to_number('12345', '99999');
> to_number
> -----------
> 12345
> (1 row)
>
> regression=# select to_number('1234 ', '99999');
> to_number
> -----------
> 1234
> (1 row)
>
> regression=# select to_number(' 1234', '99999');
> to_number
> -----------
> 1234
> (1 row)
>
> regression=# select to_number(' ', '99999');
> ERROR: invalid input syntax for type numeric: " "
> regression=# select to_number('zzzzz', '99999');
> ERROR: invalid input syntax for type numeric: " "
> regression=#
>
> The error message's report of the input string seems a tad misleading,
> especially in the last case. (Karel, is this fixable?) But anyway,
> it sure looks like the problem is bad input data.
>
> regards, tom lane
>

Thanks Tom and Richard. Yes, it is the problem of bad input data. I have
4000 rows of data and there are 10 rows containing blank string ('
'). I have to add a Where clause to carry out the SQL:

UPDATE _table
SET _bbb = to_number(substring(_aaa from 1 for 5), '99999')
WHERE _aaa <> ' ';

I guess a function checking if a string contains only numbers would be
betteroff. But I find no such functions. Checking that it's not blank
would be the only solution I can think of.

Thanks again.

regards,
Daniel Lau

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Richard Huxton 2004-01-09 20:04:48 Re: data loading
Previous Message Tom Lane 2004-01-09 14:57:25 Re: Type conversion from TEXT to DOUBLE PRECISION