Re: Check for an empty result

From: "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Check for an empty result
Date: 2009-02-13 09:17:26
Message-ID: 20090213091724.GB9263@a-kretschmer.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

In response to Eus :
> Hi Ho!
>
> Is there a way to check whether or not a subquery returns an empty result set?

You can use EXISTS for that:

-- empty result
test=*# select * from (select 1 where 1=2) foo;
?column?
----------
(0 rows)

-- check if a result exists
test=*# select exists(select * from (select 1 where 1=2) foo);
?column?
----------
f
(1 row)

test=*# select exists(select * from (select 1 where 1=1) foo);
?column?
----------
t
(1 row)

Regards, Andreas
--
Andreas Kretschmer
Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Ivan Sergio Borgonovo 2009-02-13 09:22:01 Re: TSearch queries with multiple languages
Previous Message Craig Ringer 2009-02-13 09:17:08 Re: Check for an empty result