public inbox for [email protected]  
help / color / mirror / Atom feed
From: Justin Swanhart <[email protected]>
To: Thiemo Kellner <[email protected]>
Cc: pgsql-general <[email protected]>
Subject: Re: How do I check for NULL
Date: Tue, 9 Dec 2025 17:38:32 -0500
Message-ID: <CAJM9iN3ZkwVBtJFaHmmt_oiSs07eqYN0MOstW0kFzDSCh7S6dg@mail.gmail.com> (raw)
In-Reply-To: <[email protected]>
References: <CA+FnnTw=18Rba2XgceRUFKQo5P7Xf9QhXT6wKF=DgzYT6K9-sw@mail.gmail.com>
	<[email protected]>
	<CAKFQuwbnevkxuH8JUj4cRr8ABCAwhQTT7zM4kR0X_Le3tm7KMA@mail.gmail.com>
	<[email protected]>

The key is the scalar subquery.  A scalar subquery which selects no rows
returns NULL.

https://sqlfiddle.com/postgresql/online-compiler?id=e439059a-d46d-4d49-b8ab-9ff533656066

On Tue, Dec 9, 2025, 5:33 PM Thiemo Kellner <[email protected]>
wrote:

>
> On 12/9/25 18:29, David G. Johnston wrote:
> > On Tue, Dec 9, 2025 at 10:14 AM Thiemo Kellner
> > <[email protected]> wrote:
> >
> >     I feel, you meant to say, the subquery does not return any record
> >     which is not the same as returns NULL.
> >
> >
> > For a scalar subquery the final output of a zero-row query is the null
> > value.
> >
> To me, it does not look like that (please note the empty line in the
> last example). Can you point me to the documentation saying that 0 rows
> is sometimes equal to 1 row?
>
> postgres=# select * from pg_user;
>   usename  | usesysid | usecreatedb | usesuper | userepl | usebypassrls
> |  passwd  | valuntil | useconfig
> ----------+----------+-------------+----------+---------+--------------+----------+----------+-----------
>
>
>   postgres |       10 | t           | t        | t       | t   |
> ******** |          |
> (1 row)
>
> postgres=# select usename from pg_user where false;
>   usename
> ---------
> (0 rows)
>
> postgres=# select null as usename from pg_user;
>   usename
> ---------
>
> (1 row)
>
>
>


view thread (14+ messages)

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected]
  Subject: Re: How do I check for NULL
  In-Reply-To: <CAJM9iN3ZkwVBtJFaHmmt_oiSs07eqYN0MOstW0kFzDSCh7S6dg@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox