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 18AA0D1B8C8 for ; Fri, 9 Jan 2004 08:10:49 +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 66891-02 for ; Fri, 9 Jan 2004 04:10:01 -0400 (AST) Received: from anchor-post-32.mail.demon.net (anchor-post-32.mail.demon.net [194.217.242.90]) by svr1.postgresql.org (Postfix) with ESMTP id C653DD1B484 for ; Fri, 9 Jan 2004 04:09:58 -0400 (AST) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-32.mail.demon.net with esmtp (Exim 3.35 #1) id 1AeriR-000Ap0-0W; Fri, 09 Jan 2004 08:09:59 +0000 Received: by mainbox.archonet.com (Postfix, from userid 529) id 34119178D7; Fri, 9 Jan 2004 08:09:57 +0000 (GMT) Received: from client17.archonet.com (client17.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id 6B658178D5; Fri, 9 Jan 2004 08:09:55 +0000 (GMT) From: Richard Huxton To: Daniel Lau , pgsql-sql@postgresql.org Subject: Re: Type conversion from TEXT to DOUBLE PRECISION Date: Fri, 9 Jan 2004 08:09:54 +0000 User-Agent: KMail/1.5 References: In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200401090809.55024.dev@archonet.com> X-Bogosity: No, tests=bogofilter, spamicity=0.000000, version=0.15.3 X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200401/69 X-Sequence-Number: 16462 On Friday 09 January 2004 07:35, Daniel Lau wrote: > Hi all, > > Thank you for reading this mail. > > I am trying to do the following: > Extract the first half of _aaa and put it in column _bbb > Varchar[10] | Double Precision > _aaa _bbb > 1234567890 > I used two functions to do it: substring() and to_number(). The SQL is > like this: > UPDATE _table SET _bbb = to_number(substring(_aaa from 1 for 5), '99999'); > The machine fails me and said > ERROR: invalid input syntac for type numeric: " " Works here. richardh=# \d foo Table "richardh.foo" Column | Type | Modifiers --------+-----------------------+----------- _aaa | character varying(10) | _bbb | double precision | richardh=# UPDATE foo SET _bbb = to_number(substring(_aaa from 1 for 5),'99999'); UPDATE 1 richardh=# SELECT * FROM foo richardh-# ; _aaa | _bbb ------------+------- 1234567890 | 12345 (1 row) Since your error seems to be complaining about a space, I'd guess you've got other than numeric values in _aaa. -- Richard Huxton