Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tNqqU-002ZJf-U1 for pgsql-general@arkaria.postgresql.org; Wed, 18 Dec 2024 09:59:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tNqqU-00CoIX-3t for pgsql-general@arkaria.postgresql.org; Wed, 18 Dec 2024 09:59:57 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tMsWc-00FR1H-6t for pgsql-general@lists.postgresql.org; Sun, 15 Dec 2024 17:35:27 +0000 Received: from mail.damettoluca.com ([2a01:4f8:c17:caea:bad:c0de:15:dead]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tMsWX-0030OO-Fh for pgsql-general@postgresql.org; Sun, 15 Dec 2024 17:35:26 +0000 Received: from localhost (mail.damettoluca.com [127.0.0.1]) by mail.damettoluca.com (Postfix) with ESMTP id 3F9805FFDF for ; Sun, 15 Dec 2024 18:35:20 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at mail.damettoluca.com Received: from mail.damettoluca.com ([127.0.0.1]) by localhost (mail.damettoluca.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id Vl0p73GsE09b for ; Sun, 15 Dec 2024 18:35:17 +0100 (CET) Received: from [IPv6:::ffff:10.8.0.1] (unknown [185.83.174.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.damettoluca.com (Postfix) with ESMTPSA for ; Sun, 15 Dec 2024 18:35:17 +0100 (CET) From: "Luca Dametto" To: pgsql-general@postgresql.org Subject: Documentation enancement regarding NULL and operators Date: Sun, 15 Dec 2024 17:35:16 +0000 Message-Id: Reply-To: "Luca Dametto" Disposition-Notification-To: "Luca Dametto" User-Agent: eM_Client/10.1.4828.0 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------=_MBE7AEBD0A-B7B9-41D2-BDDA-F4B500AEB45E" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --------=_MBE7AEBD0A-B7B9-41D2-BDDA-F4B500AEB45E Content-Type: multipart/alternative; boundary="------=_MB2056DE52-0708-40B4-A196-1530C11F497E" --------=_MB2056DE52-0708-40B4-A196-1530C11F497E Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable Hi All, I'm coming from hours of debugging a SQL trigger that wasn't working=20 properly. After a beautiful headache and infinite hours of documentation=20 reading I've found out that something doesn't work as I would expect. Most programming languages return "true" when two null values are=20 compared, and false when, being the two values nullable, one of them is=20 null and the other one isn't. Any developer coming from Python, Javascript, PHP (and many more) would=20 expected 'example'=3D null to return false, whilst SQL thanks to 3VL=20 returns you a gentle =C2=AF\_(=E3=83=84)_/=C2=AF . Not a true, not a false, = just nothing -=20 in a boolean statement. Python3: >>> "example" =3D=3D None False >>> None =3D=3D None True NodeJS: > "example" =3D=3D null false > null =3D=3D null true PHP 8: > var_dump("example" =3D=3D null); bool(false) > var_dump(null =3D=3D null); bool(true) Whilst I'd love to discuss the reasons of this, I understand that it=20 would be a waste of time for everyone, as we cannot change the=20 status-quo even if it made sense, as it would break many thousands of=20 projects. For that reason, I'd just like to improve the documentation to add at=20 least a note about "hey, this won't work as you might expect, because it=20 works in a different way than 99% of programming languages out there.". I've tried to understand how to submit my proposal for the documentation=20 improvements, but it's way harder than what my brain can handle with the=20 current headache caused by this stuff, I've attached a git patch to this=20 email in case it's useful. Content: " PostgreSQL follows SQL's 3VL, due to that some comparisons regarding=20 NULL values may not work as you might expect. As an example, two nullable columns that contain NULL, when compared=20 using the OPERATOR =3D, will return nothing instead of TRUE like your=20 programming language may do. In this case, only 'IS NOT DISTINCT FROM'=20 would return the result you expect. " Kind regards, Luca --------=_MB2056DE52-0708-40B4-A196-1530C11F497E Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi All,=20
I'm coming from hours of debugging a SQL trigger that wasn't working p= roperly. After a beautiful headache and infinite hours of documentation rea= ding I've found out that something doesn't work as I would expect.=20

Most programming languages return "true" when t= wo null values are compared, and false when, being the two values nullable, = one of them is null and the other one isn't.=20
Any developer coming from Python, Javascript, PHP (and many more= ) would expected 'example'=3D null to return false, whilst SQL thanks to 3V= L returns you a gentle =C2=AF\_(=E3=83=84)_/=C2=AF . Not a true, not a fals= e, just nothing - in a boolean statement.=20

Python3:
>>>=C2=A0"example" =3D=3D None
False
>>>=C2=A0None =3D=3D None
True

NodeJS:
>=C2=A0"example" =3D=3D null
false
>=C2=A0null =3D=3D null
true

PHP 8:
>=C2=A0var_dump("example" =3D=3D null);
bool(false)
>=C2=A0var_dump(null =3D=3D null);
bool(true)

Whilst I'd love to discuss the reasons of this, = I understand that it would be a waste of time for everyone, as we cannot c= hange the status-quo even if it made sense, as it would break many thousand= s of projects.=20

For that reason, I'd just like to improve the d= ocumentation to add at least a note about "hey, this won't work as you migh= t expect, because it works in a different way than 99% of programming langu= ages out there.".
I've tried to understand how to submit my proposal for the docum= entation improvements, but it's way harder than what my brain can handle wi= th the current headache caused by this stuff, I've attached a git patch to= this email in case it's useful.

Content: "
PostgreSQL follows SQL's 3VL, due to that some comparisons regar= ding NULL values may not work as you might expect.=20
As an example, two nullable columns that contain NULL, when comp= ared using the OPERATOR =3D, will return nothing instead of TRUE like your= programming language may do. In this case, only 'IS NOT DISTINCT FROM' woul= d return the result you expect.
"

Kind regards,=20
Luca=C2=A0
--------=_MB2056DE52-0708-40B4-A196-1530C11F497E-- --------=_MBE7AEBD0A-B7B9-41D2-BDDA-F4B500AEB45E Content-Type: application/octet-stream; name=0001-Improved-documentation-for-Syntax-s.-Operators-Prece.patch Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename=0001-Improved-documentation-for-Syntax-s.-Operators-Prece.patch RnJvbSA2NjJkNjg0ZDBlZGRmZmIzODEzNjllOTA5ZDhjNzBiZDcyMzAyNWFjIE1vbiBTZXAgMTcg MDA6MDA6MDAgMjAwMQpGcm9tOiBMdWNhIERhbWV0dG8gPHBvc3RncmVzcWxtYWlsaW5nQGRhbWV0 dG9sdWNhLmNvbT4KRGF0ZTogU3VuLCAxNSBEZWMgMjAyNCAxODozMzoxMyArMDEwMApTdWJqZWN0 OiBbUEFUQ0hdIEltcHJvdmVkIGRvY3VtZW50YXRpb24gZm9yIFN5bnRheCwgcy4gT3BlcmF0b3Jz IFByZWNlZGVuY2UKCi0tLQogZG9jL3NyYy9zZ21sL3N5bnRheC5zZ21sIHwgMTIgKysrKysrKysr KystCiAxIGZpbGUgY2hhbmdlZCwgMTEgaW5zZXJ0aW9ucygrKSwgMSBkZWxldGlvbigtKQoKZGlm ZiAtLWdpdCBhL2RvYy9zcmMvc2dtbC9zeW50YXguc2dtbCBiL2RvYy9zcmMvc2dtbC9zeW50YXgu c2dtbAppbmRleCA5MTYxODlhN2Q2Li43OWYzYjljZTVmIDEwMDY0NAotLS0gYS9kb2Mvc3JjL3Nn bWwvc3ludGF4LnNnbWwKKysrIGIvZG9jL3NyYy9zZ21sL3N5bnRheC5zZ21sCkBAIC0xMTExLDcg KzExMTEsNyBAQCBDQVNUICggJzxyZXBsYWNlYWJsZT5zdHJpbmc8L3JlcGxhY2VhYmxlPicgQVMg PHJlcGxhY2VhYmxlPnR5cGU8L3JlcGxhY2VhYmxlPiApCiAgICAgICAgPGVudHJ5Pjx0b2tlbj4m bHQ7PC90b2tlbj4gPHRva2VuPiZndDs8L3Rva2VuPiA8dG9rZW4+PTwvdG9rZW4+IDx0b2tlbj4m bHQ7PTwvdG9rZW4+IDx0b2tlbj4mZ3Q7PTwvdG9rZW4+I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