X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 2411256403 for ; Thu, 24 Feb 2005 08:14:38 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 32839-07 for ; Thu, 24 Feb 2005 08:14:35 +0000 (GMT) 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 5D9F856380 for ; Thu, 24 Feb 2005 08:14:34 +0000 (GMT) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-32.mail.demon.net with esmtp (Exim 4.42) id 1D4E8u-000Fdb-7k; Thu, 24 Feb 2005 08:14:40 +0000 Received: from [192.168.1.17] (client17.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id 09DEA17A58; Thu, 24 Feb 2005 08:14:39 +0000 (GMT) Message-ID: <421D8CEF.7050900@archonet.com> Date: Thu, 24 Feb 2005 08:14:39 +0000 From: Richard Huxton User-Agent: Mozilla Thunderbird 1.0 (X11/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 To: mauro Cc: pgsql-sql@postgresql.org Subject: Re: Postgres 8 - problem: invalid input syntax for integer References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.063 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200502/293 X-Sequence-Number: 20403 mauro wrote: > Hi, In previous version di Postgres (7.2) I used this table: > CREATE TABLE tablename (id serial, field int1, field2 text); > > Now this query work: > UPDATE tablename SET field1=''; (NOTE: implicit conversion to 0) > UPDATE tablename SET field2=''; > > (this cause of simple code-generation query - I don't know what's > field type) Know your field-types. If you don't know what they are, you can't handle errors elegantly anyway. > Now in postgres 8 this don't work. > Why ?(ok, it's the ufficial documentation but I don't understand... > why? it's so comfortable!) What number does '' represent? Does that mean a string of '/2' should equal your number divided by two? If not, why not? Who is providing an empty string where you've asked for a number, and why not trap this error (or store a NULL)? > Can someone help me to create a CAST to re-use this feature? Well, you could create a function: CREATE FUNCTION empty_string_is_zero(text) RETURNS integer AS ' SELECT CASE WHEN $1='''' THEN 0 ELSE $1::integer END; ' LANGUAGE SQL; UPDATE my_table SET myfield=empty_string_is_zero(''); HTH -- Richard Huxton Archonet Ltd