From: | Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> |
---|---|
To: | Joshua Berry <yoberi(at)gmail(dot)com> |
Cc: | Postgresql General Mailing list <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Providing an alternative result when there is no result |
Date: | 2009-05-18 19:21:53 |
Message-ID: | 162867790905181221y2d30008eh6326ca5109d01f2b@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hello
look on GET DIAGNOSTIC statement or FOUND variable
CREATE OR REPLACE FUNCTION foo()
RETURNS boolean AS $$
BEGIN
SELECT INTO temp_table ...
RETURN found;
END;
$$ language plpgsql;
regards
Pavel Stehule
2009/5/18 Joshua Berry <yoberi(at)gmail(dot)com>:
> Hello all,
>
> Is there an easy and efficient way to return a boolean false for a query
> that returns no result, and true for one that does return a result?
>
> Currently we select the result into a temp table.
>
> SELECT INTO temp_table id FROM ... ;
> IF temp_table IS NULL THEN
> resp:= 'NO';
> ELSE
> resp:= 'YES';
> END IF;
>
> I'd like to combine this into one step like this:
> SELECT
> CASE
> WHEN id is null THEN 'NO'::text
> ELSE 'YES'::text
> END
> FROM ...;
>
> But, this is not have SELECT's work, I suppose. The CASE is never
> encountered when there is no result, so in the "NO" case, NULL is returned.
>
> Any hints/tips? Is our original solution okay, or is there something we can
> do to improve things?
>
> Thanks,
>
> Joshua Berry
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>
From | Date | Subject | |
---|---|---|---|
Next Message | Karsten Hilbert | 2009-05-18 19:32:42 | Re: Need help |
Previous Message | Joshua Berry | 2009-05-18 19:13:56 | Providing an alternative result when there is no result |