Re: Altering built-in functions cast - Mailing list pgsql-general

From Richard Huxton
Subject Re: Altering built-in functions cast
Date
Msg-id 430ED0B3.7040604@archonet.com
Whole thread Raw
In response to Altering built-in functions cast  ("Matt A." <survivedsushi@yahoo.com>)
Responses Re: Altering built-in functions cast  ("Matt A." <survivedsushi@yahoo.com>)
List pgsql-general
Matt A. wrote:
> Anyone know how I could alter the cast of the nullif()
> function directly to return INT?
>
> We use NULLIF() for adding [1|0|null] according to the
> evalution of nullif('x','') into integer columns.
> Where x is an integer and sometimes a empty string,
> which if it's an empty string (x='') then we add NULL
> cause NULLIF says if '' == '' then return NULL

Just add a wrapper function:

CREATE FUNCTION nullif_always_int(text) RETURNS integer AS '
    SELECT nullif($1,'''')::int;
' LANGUAGE SQL;

--
   Richard Huxton
   Archonet Ltd

pgsql-general by date:

Previous
From: Martijn van Oosterhout
Date:
Subject: Re: regarding threads and transactions - problem 2
Next
From: Richard Huxton
Date:
Subject: Re: regarding threads and transactions - problem 2