Altering built-in functions cast

Lists: pgsql-general
From: "Matt A(dot)" <survivedsushi(at)yahoo(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Altering built-in functions cast
Date: 2005-08-26 00:55:30
Message-ID: 20050826005530.77061.qmail@web35201.mail.mud.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

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

Thank you,
matthew


__________________________________
Do you Yahoo!?
Yahoo! Mail - Helps protect you from nasty viruses.
http://promotions.yahoo.com/new_mail


From: Richard Huxton <dev(at)archonet(dot)com>
To: "Matt A(dot)" <survivedsushi(at)yahoo(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Altering built-in functions cast
Date: 2005-08-26 08:20:03
Message-ID: 430ED0B3.7040604@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: 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


From: "Matt A(dot)" <survivedsushi(at)yahoo(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Altering built-in functions cast
Date: 2005-08-26 08:57:40
Message-ID: 20050826085740.32324.qmail@web35207.mail.mud.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Thank you so much for the reply. I inserted the
function as you said in pgsql. I tried testing it and
got...

PERFECT RESULTS!

THHHHHHHHHHHHHAAAAAAAAAAANKKKKKKKKKKK YOUUUUUUUUUUU!

*kisses feet* j/k But honestly, Thank you very much.
You saved me from suicide.

--- Richard Huxton <dev(at)archonet(dot)com> wrote:

> 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
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 3: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faq
>


____________________________________________________
Start your day with Yahoo! - make it your home page
http://www.yahoo.com/r/hs