Re: Default value if query returns 0 rows?

From: Lars Kellogg-Stedman <lars(at)deas(dot)harvard(dot)edu>
To: Bruno Wolff III <bruno(at)wolff(dot)to>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Default value if query returns 0 rows?
Date: 2004-09-17 16:09:10
Message-ID: Pine.LNX.4.44.0409171208270.8060-100000@wolery.deas.harvard.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)deas(dot)harvard(dot)edu>
IT Operations Manager
Division of Engineering and Applied Sciences
Harvard University

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Peter Eisentraut 2004-09-17 16:09:28 Re: psql + autocommit
Previous Message Tom Lane 2004-09-17 16:08:19 Re: Default value if query returns 0 rows?