Search Postgresql Archives

Re: Altering built-in functions cast

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux