Re: Default value if query returns 0 rows? - Mailing list pgsql-general

From Lars Kellogg-Stedman
Subject Re: Default value if query returns 0 rows?
Date
Msg-id Pine.LNX.4.44.0409171208270.8060-100000@wolery.deas.harvard.edu
Whole thread Raw
In response to Re: Default value if query returns 0 rows?  (Lars Kellogg-Stedman <lars@oddbit.com>)
List pgsql-general
> Thanks for the suggestion.  I've come up with the following that appears to
> work:
>
>   SELECT
>     COALESCE((SELECT id FROM map WHERE name = $1), -1)
>     FROM map_level
>     LIMIT 1

And in fact I see that this should simply be:

  SELECT COALESCE((SELECT id FROM map WHERE name = $1), -1)

No need for me to be making things all complicated.

Thanks again!

-- Lars

--
Lars Kellogg-Stedman <lars@deas.harvard.edu>
IT Operations Manager
Division of Engineering and Applied Sciences
Harvard University




pgsql-general by date:

Previous
From: Gary Doades
Date:
Subject: Re: Default value if query returns 0 rows?
Next
From: Edmund Bacon
Date:
Subject: Re: Default value if query returns 0 rows?