Re: Best way to check if a table is empty - Mailing list pgsql-general

From David G. Johnston
Subject Re: Best way to check if a table is empty
Date
Msg-id CAKFQuwZjeeU_XOioWD+C=MzKLaeM3VUHt=g6gno3BQ7OPJxtkQ@mail.gmail.com
Whole thread Raw
In response to Re: Best way to check if a table is empty  (Christophe Pettus <xof@thebuild.com>)
List pgsql-general
On Sunday, March 23, 2025, Christophe Pettus <xof@thebuild.com> wrote:

(And to be pedantic, #1 returns TRUE / FALSE while #2 returns <int> / NULL, so they aren't exactly equivalent.  If you are able to handle <int> / NULL, you don't need the EXISTS clause.)

Leaving the limit in place, without exists #1 returns either an empty set or an <int>, never NULL.

Always returning a Boolean seems like a better API choice though; but standardizing on that final transform doesn’t change the base comparison.

David J.

pgsql-general by date:

Previous
From: Christophe Pettus
Date:
Subject: Re: Best way to check if a table is empty
Next
From: Matthias Apitz
Date:
Subject: Re: COLLATION update in 13.1