Re: BUG #18451: NULL fails to coerce to string when performing string comparison

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: "darryl(dot)dixon(at)gmail(dot)com" <darryl(dot)dixon(at)gmail(dot)com>, "pgsql-bugs(at)lists(dot)postgresql(dot)org" <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: BUG #18451: NULL fails to coerce to string when performing string comparison
Date: 2024-04-30 21:13:29
Message-ID: CAKFQuwZ0p7v7QOd_oH37P88dDUAV-wiRanE9K=6qsjG9QN+4tg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Monday, April 29, 2024, PG Bug reporting form <noreply(at)postgresql(dot)org>
wrote:

> The following bug has been logged on the website:
>
> Bug reference: 18451
> Logged by: Darryl Dixon
> Email address: darryl(dot)dixon(at)gmail(dot)com
> PostgreSQL version: 14.11
> Operating system: Ubuntu 22.04 64Bit
> Description:
>
> postdb=# select where 'ab' like '%a%';
> --
> (1 row)
>
> postdb=# select where 'ab'||NULL like '%a%';
> --
> (0 rows)
>
> postdb=# select where 'ab'||NULL::text like '%a%';
> --
> (0 rows)

You are mistaken in believing that concatenation involving null produces a
non-null result. It is rather an inherently “strict” operation.

>
> postdb=# select where 'ab'||format('%s', NULL::text) like '%a%';
> --
> (1 row)
>

Whereas format() is not “strict” and you choice of %s results in the
documented empty string substitution.

David J.

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Darryl Dixon 2024-04-30 21:25:33 Re: BUG #18451: NULL fails to coerce to string when performing string comparison
Previous Message PG Bug reporting form 2024-04-30 21:12:55 BUG #18452: [PostgreSQL and 16.1]: [Postgres.exe crash observed while installing the application]