Search Postgresql Archives

Re: Providing an alternative result when there is no result

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Merlin Moncure <mmoncure@xxxxxxxxx> writes:
> On Mon, May 18, 2009 at 3:13 PM, Joshua Berry <yoberi@xxxxxxxxx> wrote:
>> 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?

> Probably the best general approach is to:

> select count(*) = 1 from
> (
>   <query> limit 1
> )q;

Seems like EXISTS() is much more straightforward ...

> the point being that in some cases (not all obviously) the limit 1 can
> be a huge win, as you only care if there are rows or not.

... the system does know about optimizing EXISTS as if it were a LIMIT
query; you don't need to tack that on yourself.

			regards, tom lane

-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux