Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mrhWy-0003Yq-7S for pgsql-bugs@arkaria.postgresql.org; Mon, 29 Nov 2021 14:21:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mrhWQ-0001ZD-VK for pgsql-bugs@arkaria.postgresql.org; Mon, 29 Nov 2021 14:20:46 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mrhKn-0005UJ-DI for pgsql-bugs@lists.postgresql.org; Mon, 29 Nov 2021 14:08:45 +0000 Received: from mail1.politie.nl ([2a04:9a00:1200:a610::13]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mrhKj-0004D5-H0 for pgsql-bugs@lists.postgresql.org; Mon, 29 Nov 2021 14:08:44 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=politie.nl; i=@politie.nl; q=dns/txt; s=20170705; t=1638194921; x=1669730921; h=from:to:subject:date:message-id:mime-version; bh=yUm2c779ZjXkFAEAzi21NXLjCDpRnfFbgNu8ZYNRk0I=; b=KXoqORrBDFVDF58AxqJIXoi3pP5tlcdJw2RMY+jrkrXYpFpDPAFlz5D6 +clyHmVoHVcpPd36G+RIxi1oAoUAFr0bFynQ6wtMAs4OkmHXuPViDu6og POwzo3QlIfAe3TuS+2hFS22AdPfiH1VCCksRzjEr9ef+jMWBYy1oy0t12 A=; IronPort-SDR: OS9eLXTwCFNeAxzrvt//+TQilUkDWh6pkSdVKEtDF0l9PlOq7tyX8VRTWgchbuUGaEITG8NV3N CIX9TSlOmrcA== From: "Poot, Bas (B.J.)" To: "pgsql-bugs@lists.postgresql.org" Subject: subselect removes rows Thread-Topic: subselect removes rows Thread-Index: AQHX5SmzrYtFt583wEq6z1FltpkbyA== Date: Mon, 29 Nov 2021 14:08:36 +0000 Message-ID: Accept-Language: nl-NL, en-US Content-Language: nl-NL X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.0.72.117] Content-Type: multipart/alternative; boundary="_000_a5ed0b646f2e465d90954fa79d5837b5politienl_" MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --_000_a5ed0b646f2e465d90954fa79d5837b5politienl_ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi there, We recently ran into the following bug. Which is very annoying since you do= n't expect it to happen. The bug is as follows: When using certain commands in a sub-select, it removes the row. This should never happen. It should return null instead. It worked in postg= res 10, but somehow doesn't work anymore on postgres 13 (which we currently= have) Example query: select col1, col2, jsonb_each_text(col2) from ( select 1 as col1, null::jsonb as col2 union all select 1 as col1, '{"a":"2"}'::jsonb as col2 ) t1 I haven't had the opportunity to test it on postgres 14, but I couldn't fin= d anything about it in the release notes, so I don't expect it works any di= fferent in 14. The workaround is obviously simple if we could use set returning functions = in a case: select col1, col2, case when col2 is null then null else jsonb_each_text(col2) end from ( select 1 as col1, null::jsonb as col2 union all select 1 as col1, '{"a":"2"}'::jsonb as col2 ) t1 but we can't.. so that kinda makes it problematic.. Can you please look into it? Thanks, Bas Poot ------------------------- Disclaimer ---------------------------- De informatie verzonden met dit e-mailbericht (en bijlagen) is uitsluitend = bestemd voor de geadresseerde(n) en zij die van de geadresseerde(n) toestem= ming kregen dit bericht te lezen. Kennisneming door anderen is niet toegestaan. De informatie in dit e-mailbericht (en bijlagen) kan vertrouwelijk van aard= zijn en binnen het bereik van een geheimhoudingsplicht en/of een verschoni= ngsrecht vallen. Indien dit e-mailbericht niet voor u bestemd is, wordt u verzocht de afzend= er daarover onmiddellijk te informeren en het e-mailbericht (en bijlagen) t= e vernietigen. Conform het beveiligingsbeleid van de Politie wordt e-mail van en naar de p= olitie gecontroleerd op virussen, spam en phishing en moet deze e-mail vold= oen aan de voor de overheid verplichte mailbeveiligingsstandaarden die zijn= vastgesteld door het Forum Standaardisatie. Mail die niet voldoet aan het beveiligingsbeleid kan worden geblokkeerd waa= rdoor deze de geadresseerde niet bereikt. De geadresseerde wordt hiervan ni= et in kennis gesteld. --------------------------------------------------------------------- The information sent in this E-mail message (including any attachments) is = exclusively intended for the individual(s) to whom it is addressed and for = the individual(s) who has/have had permission from the recipient(s) to read= this message. Access by others is not permitted. The information in this E-mail message (including any attachments) may be o= f a confidential nature and may form part of the duty of confidentiality an= d/or the right of non-disclosure. If you have received this E-mail message in error, please notify the sender= without delay and delete the E-mail message (including any attachments). In conformity with the security policy of the Police, E-mails from and to t= he Police are checked for viruses, spam and phishing and this E-mail must m= eet the standards of the government-imposed E-mail security as set by the S= tandardization Forum. Any E-mail failing to meet said security policy may be blocked as a result = of which it will not reach the intended recipient. The recipient concerned = will not be notified. --------------------------------------------------------------------- --_000_a5ed0b646f2e465d90954fa79d5837b5politienl_ Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable

Hi there,

We recently ran into the following bug. Which is very annoying since y= ou don't expect it to happen.

The bug is as follows:
When using certain commands in a sub-select, it removes the row.
This should never happen. It should return null instead. It worked in = postgres 10, but somehow doesn't work anymore on postgres 13 (which we curr= ently have)

Example query:

select 

col1, col2, jsonb_each_text(col2) 

from (

select 1 as col1, null::jsonb as col2

union all

select 1 as col1, '{"a":"2&q= uot;}'::jsonb as col2

) t1


I haven't had the opportunity to test it on postgres 14, but I couldn'= t find anything about it in the release notes, so I don't expect it wo= rks any different in 14.

The workaround is obviously simple if we could use set returning funct= ions in a case:
select 
col1, col2, 
case 
when col2 is null then null 
else jsonb_each_text(col2) 
end
from (
select 1 as col1, null::jsonb as col2
union all
select 1 as col1, '{"a":"2&q= uot;}'::jsonb as col2
) t1

but we can't.. so that kinda makes it problematic..

Can you please look into it?

Thanks,
Bas Poot

------------------------- Disclaimer ----------------------------
De informatie verzonden met dit e-mailbericht (en bijlagen) is uitsluitend = bestemd voor de geadresseerde(n) en zij die van de geadresseerde(n) toestem= ming kregen dit bericht te lezen.
Kennisneming door anderen is niet toegestaan.
De informatie in dit e-mailbericht (en bijlagen) kan vertrouwelijk van aard= zijn en binnen het bereik van een geheimhoudingsplicht en/of een verschoni= ngsrecht vallen.
Indien dit e-mailbericht niet voor u bestemd is, wordt u verzocht de afzend= er daarover onmiddellijk te informeren en het e-mailbericht (en bijlagen) t= e vernietigen.
Conform het beveiligingsbeleid van de Politie wordt e-mail van en naar de p= olitie gecontroleerd op virussen, spam en phishing en moet deze e-mail vold= oen aan de voor de overheid verplichte mailbeveiligingsstandaarden die zijn= vastgesteld door het Forum Standaardisatie.
Mail die niet voldoet aan het beveiligingsbeleid kan worden geblokkeerd waa= rdoor deze de geadresseerde niet bereikt. De geadresseerde wordt hiervan ni= et in kennis gesteld.
---------------------------------------------------------------------
The information sent in this E-mail message (including any attachments) is = exclusively intended for the individual(s) to whom it is addressed and for = the individual(s) who has/have had permission from the recipient(s) to read= this message.
Access by others is not permitted.
The information in this E-mail message (including any attachments) may be o= f a confidential nature and may form part of the duty of confidentiality an= d/or the right of non-disclosure.
If you have received this E-mail message in error, please notify the sender= without delay and delete the E-mail message (including any attachments). In conformity with the security policy of the Police, E-mails from and to t= he Police are checked for viruses, spam and phishing and this E-mail must m= eet the standards of the government-imposed E-mail security as set by the S= tandardization Forum.
Any E-mail failing to meet said security policy may be blocked as a result = of which it will not reach the intended recipient. The recipient concerned = will not be notified.
---------------------------------------------------------------------
--_000_a5ed0b646f2e465d90954fa79d5837b5politienl_--