| From: | Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> |
|---|---|
| To: | David Frankson <David(dot)Frankson(at)infinitecampus(dot)com> |
| Cc: | "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org> |
| Subject: | Re: Extending COALESCE() |
| Date: | 2010-11-23 05:06:57 |
| Message-ID: | AANLkTinBOWypD=XMvjmeKHYfc4yZ=Z+vc-pm=kWrCM0C@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
Hello
I am afraid, so this isn't possible. You have to use a explicit cast
"int to bool"
select coalesce(true, 0::bool)
regards
Pavel Stehule
2010/11/23 David Frankson <David(dot)Frankson(at)infinitecampus(dot)com>:
> 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
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Armand Turpel | 2010-11-23 07:54:29 | json data type |
| Previous Message | Jayadevan M | 2010-11-23 03:47:36 | Re: Debug advice when postgres connection maxing out |