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 6A068D1B49E for ; Fri, 9 Jan 2004 07:48:40 +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 64031-04 for ; Fri, 9 Jan 2004 03:47:51 -0400 (AST) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id E8CE7D1B457 for ; Fri, 9 Jan 2004 03:47:49 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.10/8.12.10) with ESMTP id i097lo19021667; Fri, 9 Jan 2004 02:47:50 -0500 (EST) To: Daniel Lau Cc: pgsql-sql@postgresql.org Subject: Re: Type conversion from TEXT to DOUBLE PRECISION In-reply-to: References: Comments: In-reply-to Daniel Lau message dated "Fri, 09 Jan 2004 15:35:20 +0800" Date: Fri, 09 Jan 2004 02:47:50 -0500 Message-ID: <21666.1073634470@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200401/68 X-Sequence-Number: 16461 Daniel Lau writes: > 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 for me ... regression=# create table _table (_aaa varchar(10), _bbb double precision); CREATE TABLE regression=# insert into _table values('1234567890', null); INSERT 180987 1 regression=# UPDATE _table SET _bbb = to_number(substring(_aaa from 1 for 5), '99999'); UPDATE 1 regression=# select * from _table; _aaa | _bbb ------------+------- 1234567890 | 12345 (1 row) regression=# I don't think you have accurately described what you did. regards, tom lane