Re: Cast null to int4 upgrading from Version 7.2 - Mailing list pgsql-patches

From Jim Nasby
Subject Re: Cast null to int4 upgrading from Version 7.2
Date
Msg-id F366047D-42EA-46C8-9DA2-360698CDF3F8@decibel.org
Whole thread Raw
In response to Re: Cast null to int4 upgrading from Version 7.2  (Neil Conway <neilc@samurai.com>)
Responses Re: Cast null to int4 upgrading from Version 7.2
List pgsql-patches
On Nov 16, 2006, at 3:10 PM, Neil Conway wrote:
> Yes, this is a common problem for people upgrading from 7.2. I
> think the
> long-term fix is to change your queries: comparing an integer with
> '' is
> not sensible. That is:
>
> SELECT * FROM employee_table WHERE employee_id = 0;
>
> is the right way to write that query.
>
> As a temporary fix, I suppose you could hack pg_atoi() to treat an
> empty
> string as zero (src/backend/utils/adt/numutils.c).

As a less invasive alternative, I *think* you could create an SQL
function for casting text to int that treated '' as 0, and then
replace the built-in CAST with that. You'd also need to make the cast
implicit, which could cause other problems.

20k lines of code isn't all that much, though... you'll be much
better off fixing it.
--
Jim Nasby                                            jim@nasby.net
EnterpriseDB      http://enterprisedb.com      512.569.9461 (cell)



pgsql-patches by date:

Previous
From: Tom Lane
Date:
Subject: Proposed patch for xact-vs-multixact bugs
Next
From: Peter Eisentraut
Date:
Subject: Re: Cast null to int4 upgrading from Version 7.2