Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f9toc-0003bX-6y for pgsql-bugs@arkaria.postgresql.org; Sat, 21 Apr 2018 14:48:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1f9toa-0006C3-98 for pgsql-bugs@arkaria.postgresql.org; Sat, 21 Apr 2018 14:48:36 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f9nL1-0005P8-Sq for pgsql-bugs@lists.postgresql.org; Sat, 21 Apr 2018 07:53:40 +0000 Received: from sonic303-20.consmr.mail.ne1.yahoo.com ([66.163.188.146]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f9nKy-0004Et-Qi for pgsql-bugs@lists.postgresql.org; Sat, 21 Apr 2018 07:53:38 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1524297215; bh=4PI+zG72VmczpVcm/C1PUGUfdjEitgqC1mwksW80sTY=; h=Date:From:To:In-Reply-To:References:Subject:From:Subject; b=r6JEbVT+M3axZaMFj5wGcicSqIAQBhmfeqgnKDrUADJ9WGfMjt5iZ/abNvTwiFbaOEozrsOdMdlgSY4skPsYK7zcdIEHtbNcZQCjbChj7Sq8N1blqtQztYYVq1vrJqI+f5IPSEt34YO9KgRBl1IHBlJYyqiA/BUF1gACltHcpltpsM99oiism+1WtkHGxILuBZ5JfzKLFbQZS9Ae+1wDpfg5w3QYl4whOptC/rzDv6bS6C+iW9G4nQymjSePoaEC0mmbITP5HUmjqMwUYwjyUyi35CVWOnbCjnVhjYsqXKibdtEDsko0203wnCwaoKVnquUvsanHGjj8li2e9L+C/g== X-YMail-OSG: 7nROxd8VM1nQ.7E5ybGBjcwtlKlNOzAesAZs7ZBRUkmhDvJWM2keZH_Fd3NeMpQ kZwqX7d_XM00zLv4tUa8uErpulwAwfB5BKOzJuAGIBzU0TDdLYKuDCZb2ay6R19IEsfohdSGWzCq 79VobxEFz.MROkM2V7x8OuJIWxj.iZgb6fX5yjWaz.WTubuQprpLPa.J59iXIgBGZKZKrZcOZuLQ Mrle2p8TdtZBz2LqFK.JqFTazLlAxIyiCpWK_aMl08vjGPSvzspNrPBem4oQqyoCumAuy3a_.uDI CqIzsS7YdVywVmfYxZ3qMKYNClyyKTaDMRJjxUDLAur41WZqG5O3sl5ikv1hF80CdPZisepINZo5 9n2IQs1niO5HBifmRUxeLZna6HTBtdZQtRgJ54eXMFiTckuKzji05fH0FQ.yo9wCZFP..kogx2df dvlV13dXojxo2aaK2osV.5Y3jlOVCpUHE7JdWr_0vvmGvnmlNf5LSge_A9j10MZ4zPx2kgqPXUvy g3d6JYSpDEo8gFgrucNBRWOF7V_pfvjpd9e5U55uLnlj_j7s- Received: from sonic.gate.mail.ne1.yahoo.com by sonic303.consmr.mail.ne1.yahoo.com with HTTP; Sat, 21 Apr 2018 07:53:35 +0000 Date: Sat, 21 Apr 2018 07:51:37 +0000 (UTC) From: Alex To: pgsql-bugs@lists.postgresql.org, Andrew Gierth Message-ID: <1036187715.3416683.1524297097829@mail.yahoo.com> In-Reply-To: <87wox1chvh.fsf@news-spur.riddles.org.uk> References: <152426142167.459.1224353227133000998@wrigleys.postgresql.org> <87wox1chvh.fsf@news-spur.riddles.org.uk> Subject: Re: BUG #15166: PL/PGSQL default rowtype variable value is null but also not null MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_3416682_218209015.1524297097826" X-Mailer: WebService/1.1.11782 YMailNorrin Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0 Content-Length: 6510 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk ------=_Part_3416682_218209015.1524297097826 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Thank you for clarification. This issue can be closed. On Saturday, April 21, 2018, 7:45:45 AM GMT+3, Andrew Gierth wrote: =20 =20 >>>>> "PG" =3D=3D PG Bug reporting form writes: PG> Running the following script will report that 'var' is null but PG> also not null: PG> create table test_table(); This creates a table with no columns. Such an object isn't valid in the SQL spec, but if you extend the spec's definition of how IS NULL and IS NOT NULL are required to work to the zero-column case, it turns out that a value of such a table's rowtype can be simultaneously NULL and NOT NULL: =C2=A0 - a composite value IS NULL either if it is the null value, or every =C2=A0 =C2=A0 one of its column values is the null value. By long-standing =C2=A0 =C2=A0 convention in logic, "every" is vacuously true when applied t= o the =C2=A0 =C2=A0 empty set, so a composite value of degree 0 always passes the= IS =C2=A0 =C2=A0 NULL test. =C2=A0 - a composite value IS NOT NULL if it is not the null value and none =C2=A0 =C2=A0 of its column values is the null value. "None of" is once mor= e =C2=A0 =C2=A0 vacuously true when there are no columns, so a composite valu= e of =C2=A0 =C2=A0 degree 0 passes IS NOT NULL if and only if it is not the null= value. The spec is quite explicit that IS NULL and IS NOT NULL are inverses of each other only if the operand is of degree exactly 1 (i.e. is a scalar or a row value with exactly 1 column). PG> By documentation, it should be null: "If the DEFAULT clause is not PG> given then the variable is initialized to the SQL null value." That could be considered a slight bug in the documentation, because what actually happens for rowtype variables is that they are initialized to a row value with all null columns, NOT to the null value. In most cases the difference is somewhat hard to spot. Also, it looks like this behavior changes in pg11, probably not intentionally. Relying on it either way seems dangerous (in fact relying on anything at all to do with zero-column tables seems dangerous). --=20 Andrew (irc:RhodiumToad) =20 ------=_Part_3416682_218209015.1524297097826 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Thank you for clarification.
This issue can be closed.<= br>
=20
=20
On Saturday, April 21, 2018, 7:45:45 AM GMT+3, Andr= ew Gierth <andrew@tao11.riddles.org.uk> wrote:


>>>>> "PG" =3D=3D = PG Bug reporting form <noreply@postgresql.org> writes:

PG> Running the fol= lowing script will report that 'var' is null but
= PG> also not null:

PG> create table test_table();

This creates a table with no columns. Such an object isn't va= lid in the
SQL spec, but if you extend the spec's= definition of how IS NULL and IS
NOT NULL are re= quired to work to the zero-column case, it turns out that
a value of such a table's rowtype can be simultaneously NULL and N= OT
NULL:

  - a composite value IS NULL either if it is the null va= lue, or every
    one of its column val= ues is the null value. By long-standing
  &n= bsp; convention in logic, "every" is vacuously true when applied to the
=
    empty set, so a composite value of deg= ree 0 always passes the IS
    NULL tes= t.

  - a composit= e value IS NOT NULL if it is not the null value and none
    of its column values is the null value. "None of" is= once more
    vacuously true when ther= e are no columns, so a composite value of
  =   degree 0 passes IS NOT NULL if and only if it is not the null value.=

The spec is quite exp= licit that IS NULL and IS NOT NULL are inverses of
each other only if the operand is of degree exactly 1 (i.e. is a scalar
or a row value with exactly 1 column).

PG> By documentation, it shou= ld be null: "If the DEFAULT clause is not
PG>= given then the variable is initialized to the SQL null value."

That could be considered a slight= bug in the documentation, because what
actually = happens for rowtype variables is that they are initialized to a
row value with all null columns, NOT to the null value. In m= ost cases
the difference is somewhat hard to spot= .

Also, it looks like = this behavior changes in pg11, probably not
inten= tionally. Relying on it either way seems dangerous (in fact relying
on anything at all to do with zero-column tables seems d= angerous).

--
Andrew (irc:RhodiumToad)
------=_Part_3416682_218209015.1524297097826--