| From: | Justin Swanhart <greenlion(at)gmail(dot)com> |
|---|---|
| To: | Thiemo Kellner <thiemo(at)gelassene-pferde(dot)biz> |
| Cc: | pgsql-general <pgsql-general(at)lists(dot)postgresql(dot)org> |
| Subject: | Re: How do I check for NULL |
| Date: | 2025-12-09 22:38:32 |
| Message-ID: | CAJM9iN3ZkwVBtJFaHmmt_oiSs07eqYN0MOstW0kFzDSCh7S6dg@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
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 <thiemo(at)gelassene-pferde(dot)biz>
wrote:
>
> On 12/9/25 18:29, David G. Johnston wrote:
> > On Tue, Dec 9, 2025 at 10:14 AM Thiemo Kellner
> > <thiemo(at)gelassene-pferde(dot)biz> 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)
>
>
>
| From | Date | Subject | |
|---|---|---|---|
| Next Message | ma lz | 2025-12-10 02:27:25 | strict-aliasing warning |
| Previous Message | Thiemo Kellner | 2025-12-09 22:33:13 | Re: How do I check for NULL |