Re: Cast null to int4 upgrading from Version 7.2

From: Jim Nasby <decibel(at)decibel(dot)org>
To: Neil Conway <neilc(at)samurai(dot)com>
Cc: demmons(at)instantbenefits(dot)com, pgsql-patches(at)postgresql(dot)org, 'Jason Rutherford' <jasonr(at)instantbenefits(dot)com>, Dave Horn <dhorn(at)instantbenefits(dot)com>
Subject: Re: Cast null to int4 upgrading from Version 7.2
Date: 2006-11-17 03:48:49
Message-ID: F366047D-42EA-46C8-9DA2-360698CDF3F8@decibel.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers 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(at)nasby(dot)net
EnterpriseDB http://enterprisedb.com 512.569.9461 (cell)

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2006-11-17 05:01:06 Re: [PATCHES] replication docs: split single vs. multi-master
Previous Message Jim Nasby 2006-11-17 01:48:58 Re: [HACKERS] Replication documentation addition

Browse pgsql-patches by date

  From Date Subject
Next Message Bruce Momjian 2006-11-17 05:01:06 Re: [PATCHES] replication docs: split single vs. multi-master
Previous Message Tom Lane 2006-11-17 01:23:35 Proposed patch for xact-vs-multixact bugs