Extending COALESCE()

From: David Frankson <David(dot)Frankson(at)infinitecampus(dot)com>
To: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Extending COALESCE()
Date: 2010-11-23 00:40:48
Message-ID: DC57CFF048A13045B63DA5D831B526BC07F48EC8B2@ANDY.InfiniteCampus.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Is it possible to extend the COALESCE() function? I would like to support for coalescing an int into a Boolean, but I get syntax errors if I don't wrap coalesce in quotes.

CREATE OR REPLACE FUNCTION coalesce(boolean,int) RETURNS boolean AS $$

SELECT CASE WHEN $1 IS NOT NULL THEN $1 WHEN $2 = 1 THEN true ELSE false END

$$ LANGUAGE sql IMMUTABLE;

Thanks,

Dave

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Dan Kortschak 2010-11-23 03:39:19 very basic SQL question
Previous Message Jim Kunkel 2010-11-22 22:47:29 gap between error and cure