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 1sE3nE-00GxAL-FX for pgsql-hackers@arkaria.postgresql.org; Mon, 03 Jun 2024 09:15:54 +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 1sE3nE-009jZg-7T for pgsql-hackers@arkaria.postgresql.org; Mon, 03 Jun 2024 09:15:52 +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 1sE3nC-009jZY-VB for pgsql-hackers@lists.postgresql.org; Mon, 03 Jun 2024 09:15:51 +0000 Received: from wfout3-smtp.messagingengine.com ([64.147.123.146]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sE3n6-0026jN-UQ for pgsql-hackers@lists.postgresql.org; Mon, 03 Jun 2024 09:15:49 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfout.west.internal (Postfix) with ESMTP id 4337F1C000FE; Mon, 3 Jun 2024 05:15:41 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Mon, 03 Jun 2024 05:15:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eisentraut.org; h=cc:cc:content-transfer-encoding:content-type:content-type :date:date:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:subject:subject:to:to; s=fm3; t=1717406140; x=1717492540; bh=QGrOmd76ZsPMyHkuVt7/ssTZRKxLCC30 sQLa/QTfDiA=; b=VzfNvbe1rO5qsgxgfXp/ESW0M4z4BhVxBv/511DfjiSQoN7k B42qsybZOAvJM46PERJ5QV2r6rcJ6USlDNvABev9jdUzdIRurbkE+F13iqRO48Ei XqI+OdJCoTfvv93ZXTHmhtCDYsRH52Z3AILJfnPPPayTE1BysEVqe9rvSMdXbve2 kNm4Z4pHDwfYOtyWQikrYelpFNfurnWi4Q8xjdjyH8tyc6P6HtEVVfucwxp3DIMl wBtQyHEYdDzrS3mDcbbAy5h9abyd9NbY/hZac+tP40v6VnN4rmXLq6ynB3cUovQf xW9zlaegKn9aWWkGR/dMsMJsNq5PFiOgmVSbCg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1717406140; x= 1717492540; bh=QGrOmd76ZsPMyHkuVt7/ssTZRKxLCC30sQLa/QTfDiA=; b=O Hx0k9xM2R9YNkyfL8bK3dT2ZIOlqJbSF5aLr2O5XqfH/blDmmaZVKKt426EjhvZR B0hKUuUR1Ji1oUuLLpmZfglnc4KFSxMEGHoK0rsC/lwOqDDgI1YdWIyu5V1pX6e2 Uie+rKNrva+w7+uEnefLutXeVlIsawk3/Jf04EO7wNsTk798fDqe1xrc+EaAdMaf sN+L9uG402We/9GvJqdo/q68bR1NHwdtBWBHMuZXrJTMfuoZ/OQYscWc0Og8gwpS DbGw5Vl5zwNeOWS0W2L6w3gzsq5hNopI975IjWDCIUFgkdkCqEZPmtWE/23kgADm tDnwzcaA1F/Hzv8RwUgcg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdelvddgudegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepkfffgggfuffvvehfhfgjtgfgsehtkeertddtvdejnecuhfhrohhmpefrvght vghrucfgihhsvghnthhrrghuthcuoehpvghtvghrsegvihhsvghnthhrrghuthdrohhrgh eqnecuggftrfgrthhtvghrnhepteffheeivdeujeelvefhveeffefhjeevffdugfejgfdt udfftdfhffejhefgtedunecuffhomhgrihhnpehorhgrtghlvgdrtghomhenucevlhhush htvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpvghtvghrsegvihhs vghnthhrrghuthdrohhrgh X-ME-Proxy: Feedback-ID: ie0a040ee:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 3 Jun 2024 05:15:39 -0400 (EDT) Message-ID: <65d2544e-4a11-448d-9683-7bce0d43565d@eisentraut.org> Date: Mon, 3 Jun 2024 11:15:37 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: pgsql: Add more SQL/JSON constructor functions To: Tom Lane Cc: Amit Langote , Alvaro Herrera , pgsql-hackers@lists.postgresql.org References: <202405271313.qkl63gffldmx@alvherre.pgsql> <202405271326.5a5rprki64aw@alvherre.pgsql> <3189.1717001075@sss.pgh.pa.us> <50a780ab-f1a4-4c5f-b9a1-88a174cf12af@eisentraut.org> <2416639.1717389996@sss.pgh.pa.us> Content-Language: en-US From: Peter Eisentraut In-Reply-To: <2416639.1717389996@sss.pgh.pa.us> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 02.06.24 21:46, Tom Lane wrote: > If you don't > like our current behavior, then either you have to say that RETURNING > with a length-limited target type is illegal (which is problematic > for the spec, since they have no such type) or that the cast behaves > like an implicit cast, with errors for overlength input (which I find > to be an unintuitive definition for a construct that names the target > type explicitly). It asks for the latter behavior, essentially (but it's not defined in terms of casts). It says: """ ii) Let JV be an implementation-dependent (UV097) value of type TT and encoding ENC such that these two conditions hold: 1) JV is a JSON text. 2) When the General Rules of Subclause 9.42, “Parsing JSON text”, are applied with JV as JSON TEXT, FO as FORMAT OPTION, and WITHOUT UNIQUE KEYS as UNIQUENESS CONSTRAINT; let CST be the STATUS and let CSJI be the SQL/JSON ITEM returned from the application of those General Rules, CST is successful completion (00000) and CSJI is an SQL/JSON item that is equivalent to SJI. If there is no such JV, then let ST be the exception condition: data exception — invalid JSON text (22032). iii) If JV is longer than the length or maximum length of TT, then an exception condition is raised: data exception — string data, right truncation (22001). """ Oracle also behaves accordingly: SQL> select json_serialize('{"a":1, "a":2}' returning varchar2(20)) from dual; JSON_SERIALIZE('{"A" -------------------- {"a":1,"a":2} SQL> select json_serialize('{"a":1, "a":2}' returning varchar2(5)) from dual; select json_serialize('{"a":1, "a":2}' returning varchar2(5)) from dual * ERROR at line 1: ORA-40478: output value too large (maximum: 5) JZN-00018: Input to serializer is too large Help: https://docs.oracle.com/error-help/db/ora-40478/ As opposed to: SQL> select cast(json_serialize('{"a":1, "a":2}') as varchar2(5)) from dual; CAST( ----- {"a":