Re: Postgres 8 - problem: invalid input syntax for integer

From: Richard Huxton <dev(at)archonet(dot)com>
To: mauro <bertolima(at)yahoo(dot)it>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Postgres 8 - problem: invalid input syntax for integer
Date: 2005-02-28 09:34:19
Message-ID: 4222E59B.3050205@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Din Adrian 2005-02-28 10:43:11 Re: SQL error: function round(double precision, integer) does not exist
Previous Message Andreas Kretschmer 2005-02-28 09:12:53 Re: [despammed] SQL error: function round(double precision, integer) does not exist