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 1qseEc-008nLX-C3 for pgsql-hackers@arkaria.postgresql.org; Tue, 17 Oct 2023 07:11:22 +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 1qseEZ-007DA9-Py for pgsql-hackers@arkaria.postgresql.org; Tue, 17 Oct 2023 07:11:20 +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 1qseEZ-007DA1-Bg for pgsql-hackers@lists.postgresql.org; Tue, 17 Oct 2023 07:11:20 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by magus.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qseET-0018OX-K0 for pgsql-hackers@postgresql.org; Tue, 17 Oct 2023 07:11:19 +0000 Received: from [192.168.100.8] (109-252-88-77.nat.spd-mgts.ru [109.252.88.77]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) (Authenticated sender: a.melnikov@postgrespro.ru) by mail.postgrespro.ru (Postfix/587) with ESMTPSA id 47090E20E74; Tue, 17 Oct 2023 10:11:13 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mx2023; t=1697526673; bh=woDkhot+XiRBws5OvNhZb1s4X5Iw8ZnNzF7yoKXkhJI=; h=Message-ID:Date:User-Agent:Subject:To:Cc:References:From: In-Reply-To:From; b=Y4ineNGPaPmdzR6SaLfXeWXhkQEwsWlXwbYXlf8Pbxx17LwBT07sxszJM1zERNsGf BM5dMhEUdh8uknIuPYlOne9RuDZeaM3wAVY9Gk1ZpYcVJZEfPU2mpH2mmYBeoMnHJL s89i3O8LN0wVhyYKu0icFXtkHijZoSP4MLYCX0mpq1btLiV0oJ3aGBpqICvfbzsTLD tkuZ5w9uo1XDIQ49pF1j6q5JJNyEM1X2DhxrwMGWahDuBTUk1O33YTZJUWJ0buWF/T 8M7YV9CXXc6HWu6XhqNqj65Jqijxs9KhJ541VypFKx/FEfdZWZceBHy/KJ8Se3FaLT LNXhUzcvi591A== Message-ID: <1156d735-5a1b-4c5e-8e13-44b15ec1ee21@postgrespro.ru> Date: Tue, 17 Oct 2023 10:11:12 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: remaining sql/json patches Content-Language: en-US To: Amit Langote Cc: jian he , Nikita Malakhov , Andres Freund , Alvaro Herrera , Andrew Dunstan , Erik Rijkers , PostgreSQL-development References: <202309281104.kmkr4v34ny2t@alvherre.pgsql> <20231006214856.yie5dedhzrcb3qxx@alap3.anarazel.de> From: "Anton A. Melnikov" In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 17.10.2023 07:02, Amit Langote wrote: > One thing jian he missed during the debugging is that > ExecEvalJsonExprCoersion() receives the EMPTY ARRAY value via > *op->resvalue/resnull, set by ExecEvalJsonExprBehavior(), because > that's the ON EMPTY behavior specified in the constraint. The bug was > that the code in ExecEvalJsonExprCoercion() failed to set val_string > to that value ("[]") before passing to InputFunctionCallSafe(), so the > latter would assume the input is NULL. > Thank a lot for this remark! I tried to dig to the transformJsonOutput() to fix it earlier at the analyze stage, but it looks like a rather hard way. Maybe simple in accordance with you note remove the second condition from this line: if (jb && JB_ROOT_IS_SCALAR(jb)) ? There is a simplified reproduction before such a fix: postgres=# select JSON_QUERY(jsonb '[]', '$' RETURNING char(5) OMIT QUOTES EMPTY ON EMPTY); server closed the connection unexpectedly This probably means the server terminated abnormally after: postgres=# select JSON_QUERY(jsonb '[]', '$' RETURNING char(5) OMIT QUOTES EMPTY ON EMPTY); json_query ------------ [] (1 row) And at the moment i havn't found any side effects of that fix. Please point me if i'm missing something. With the best wishes! -- Anton A. Melnikov Postgres Professional: http://www.postgrespro.com The Russian Postgres Company