Re: Default value if query returns 0 rows?

From: Csaba Nagy <nagy(at)ecircle-ag(dot)com>
To: lars(at)oddbit(dot)com
Cc: Postgres general mailing list <pgsql-general(at)postgresql(dot)org>
Subject: Re: Default value if query returns 0 rows?
Date: 2004-09-17 16:22:33
Message-ID: 1095438153.3661.33.camel@localhost.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

[snip]
> Another way is a subselect:
>
> select coalesce((select id from map where name = 'foo'), -1);
Then why not:

select coalesce((select id from map where name = 'foo' limit 1), -1);

This should work even if there are more rows with foo.

>
> but this one will actively blow up if there are multiple 'foo' rows,
> so it doesn't solve that problem either.
>
> regards, tom lane
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message John Sidney-Woollett 2004-09-17 16:26:50 Re: psql + autocommit
Previous Message Björn Lundin 2004-09-17 16:13:30 Re: Postgresql <--> webservices?