On Fri, 17 Sep 2004, Bruno Wolff III wrote:

> > 
> >   if exists (select 1 from map where name = 'foo') then
> >     select id from map where name = 'foo'
> >   else
> >     select -1
> >   end if
> > 
> 
> If there can be at most one match you can use a subselect and coalesce.
> 

Bruno,

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

-- Lars

-- 
Lars Kellogg-Stedman <[EMAIL PROTECTED]>



---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

               http://www.postgresql.org/docs/faqs/FAQ.html

Reply via email to