X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (neptune.hub.org [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 38A50D1BA62 for ; Fri, 9 Jan 2004 17:16:05 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 39194-07 for ; Fri, 9 Jan 2004 13:15:34 -0400 (AST) Received: from mx3.ust.hk (mx3.ust.hk [143.89.13.11]) by svr1.postgresql.org (Postfix) with ESMTP id 91D45D1DDBB for ; Fri, 9 Jan 2004 11:44:58 -0400 (AST) Received: from uststf1 (uststf1.ust.hk [143.89.14.111]) by mx3.ust.hk (8.12.10/8.12.10) with SMTP id i09FiaFQ055637; Fri, 9 Jan 2004 23:44:36 +0800 (HKT) Date: Fri, 9 Jan 2004 23:44:36 +0800 (HKT) From: Daniel Lau X-Sender: iedaniel@uststf1 To: Tom Lane Cc: Richard Huxton , pgsql-sql@postgresql.org, Karel Zak Subject: Re: Type conversion from TEXT to DOUBLE PRECISION In-Reply-To: <23739.1073660245@sss.pgh.pa.us> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200401/72 X-Sequence-Number: 16465 On Fri, 9 Jan 2004, Tom Lane wrote: > Richard Huxton 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