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 0E7785664C for ; Mon, 28 Feb 2005 09:34:25 +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 27895-08 for ; Mon, 28 Feb 2005 09:34:23 +0000 (GMT) Received: from anchor-post-35.mail.demon.net (anchor-post-35.mail.demon.net [194.217.242.85]) by svr1.postgresql.org (Postfix) with ESMTP id 9DB2F565F2 for ; Mon, 28 Feb 2005 09:34:23 +0000 (GMT) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-35.mail.demon.net with esmtp (Exim 4.42) id 1D5hGH-000DM6-J0; Mon, 28 Feb 2005 09:32:22 +0000 Received: from [192.168.1.17] (client17.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id 7045C16600; Mon, 28 Feb 2005 09:34:20 +0000 (GMT) Message-ID: <4222E59B.3050205@archonet.com> Date: Mon, 28 Feb 2005 09:34:19 +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: <421D8CEF.7050900@archonet.com> 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.062 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200502/360 X-Sequence-Number: 20470 mauro wrote: >>What number does '' represent? > > 'No response' value... Would've been better to have a genuine response_provided flag, but then you obviously know that. >>Who is providing an empty string where you've asked for a number, and >>why not trap this error (or store a NULL)? > > You are certainly right. My problem concerns the compatibility of code > among postgres 8 and 7.2 that I wanted to maintain. The existing code > (data analysis) exploits the particularity that the null ('') becomes > 0 (ok, no comment :) ) logically wrong but practically perfect! Your best choice is probably to tweak your application and translate '' to NULL? Then you could add a before trigger to the table to replace NULL with 0. > [...CAST CODE...] > > Thank you for the explicit-cast code, but I want reproduce it in > 'database level' so I don't use explicit cast but IMPLICIT; everytime > updating integer fields with '' values it cast to (0 or NULL). If you can't do the above, you've got three options: 1. Stay with PG version 7.2 2. Write your own type, with in/out functions that map '' to 0 3. Hack the code to replace the ''=>0 conversion - you could probably identify the old code from CVS. Obviously the null+trigger option is better than these three. Of these three though, number 2 is probably the cleanest solution. -- Richard Huxton Archonet Ltd