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 1rXDVC-009M1r-AJ for pgsql-hackers@arkaria.postgresql.org; Tue, 06 Feb 2024 04:56:10 +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 1rXDV9-000Qxo-8y for pgsql-hackers@arkaria.postgresql.org; Tue, 06 Feb 2024 04:56:07 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rXDV8-000Qxf-Vg for pgsql-hackers@lists.postgresql.org; Tue, 06 Feb 2024 04:56:06 +0000 Received: from mail-vs1-xe2a.google.com ([2607:f8b0:4864:20::e2a]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rXDV6-005Ihe-Ij for pgsql-hackers@postgresql.org; Tue, 06 Feb 2024 04:56:05 +0000 Received: by mail-vs1-xe2a.google.com with SMTP id ada2fe7eead31-46d37c74f53so367893137.3 for ; Mon, 05 Feb 2024 20:56:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707195364; x=1707800164; darn=postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=eD3uDGQ11/4f66E4wLMfOwiZXH57zi0oHdKAaczniuQ=; b=Q049pOezmeUC/5TRdHrdno24jf3f/bK1lNh6k8whzQhz224tiLB/2qh5PFxFaWh2GB Cxb1n97zExIbeigWPSOiSwKJyE5/rgj506SJVFbHcWWOJnt8de13vMt1DqUlzqgGUYI3 vKblidlx2qa6IceBj2jLYrS7FGPOjNJogjUPLWY1PpyC8Q8vUpgrrFU5X94mRfMCiLvm 3CQ+ZnJcJJZ32cmCah7Iw9lhfGCOWptcpLmjROgy2KjvsevmvbTpFD2IJ9M91uQEBgRZ +HO/Ab1nLZT4YnxTcfzU8j2j1660OMbsTk68uEw3+KyiAwaAgRJEZ1/K0f52R4lUW/Pv H1yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707195364; x=1707800164; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eD3uDGQ11/4f66E4wLMfOwiZXH57zi0oHdKAaczniuQ=; b=tlIiEOxtc4XFrtGvzE+BV6JMTlqK7FVyOZkIqu6suQp0PCFR99Mz60LY0wbaoyOMpp 0lQVXFvSdYqo0M3VWHCJARgE1aNaAt+6SM5zIimTJop/w3VBLhIaJC1urtK0Owz4nl1Z VilWity3Q6WzfK9Gqy5zyJDu0cnyzqk4zH4qsDF1M0c+VUdUTHa/liJEwFEzZvbRCL6x +FcZckrsBbydRgi6qy8gqFuepEwgggDdHONOK7LQnyopwYnr3+R/OajrM/mmPlQQtrfy 5qzaqQKqI+AvF+Ufby9ZpMTAIbnIkp+b8pPb7BdjW+CM23QviUJklLIOLVTTd3nnGQdb BdiA== X-Gm-Message-State: AOJu0YyXOq96JEuCojD9ImVLmX224yMr24M2ZFE9Gio6YpfRg2ADQtGd lFNc2kYShYAPOo3Mbu9UVnW34eBPuY4kJJ2XWK6NqDCb+CpP6aRbH98OroTPvQPmVWZzvB3q4vs kW1SYXoNvRFWnblPskyb9zpljygQ= X-Google-Smtp-Source: AGHT+IGy7aet8+zxD+8pyVjjVSasZ9Bt9dqgwnD5hSBDbeslw3iVE8J+PPqbrHEQqhYUAin+t5L6EhmeHUzRi+i68uY= X-Received: by 2002:a05:6102:34e3:b0:46d:238b:7b5e with SMTP id bi3-20020a05610234e300b0046d238b7b5emr2064570vsb.0.1707195363699; Mon, 05 Feb 2024 20:56:03 -0800 (PST) MIME-Version: 1.0 References: <202401181711.qxjxpnl3ohnw@alvherre.pgsql> <202401221619.ragf2vnbyopl@alvherre.pgsql> In-Reply-To: From: jian he Date: Tue, 6 Feb 2024 12:55:51 +0800 Message-ID: Subject: Re: remaining sql/json patches To: Amit Langote Cc: Alvaro Herrera , Andres Freund , Erik Rijkers , Andrew Dunstan , PostgreSQL-development Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Jan 25, 2024 at 10:39=E2=80=AFPM jian he wrote: > > On Thu, Jan 25, 2024 at 7:54=E2=80=AFPM Amit Langote wrote: > > > > > > > > The problem with returning comp_domain_with_typmod from json_value() > > > seems to be that it's using a text-to-record CoerceViaIO expression > > > picked from JsonExpr.item_coercions, which behaves differently than > > > the expression tree that the following uses: > > > > > > select ('abcd', 42)::comp_domain_with_typmod; > > > row > > > ---------- > > > (abc,42) > > > (1 row) > > > > Oh, it hadn't occurred to me to check what trying to coerce a "string" > > containing the record literal would do: > > > > select '(''abcd'', 42)'::comp_domain_with_typmod; > > ERROR: value too long for type character(3) > > LINE 1: select '(''abcd'', 42)'::comp_domain_with_typmod; > > > > which is the same thing as what the JSON_QUERY() and JSON_VALUE() are > > running into. So, it might be fair to think that the error is not a > > limitation of the SQL/JSON patch but an underlying behavior that it > > has to accept as is. > > > > Hi, I reconciled with these cases. > What bugs me now is the first query of the following 4 cases (for compari= son). > SELECT JSON_QUERY(jsonb '[1,2]', '$' RETURNING char(3) omit quotes); > SELECT JSON_QUERY(jsonb '[1,2]', '$' RETURNING char(3) keep quotes); > SELECT JSON_QUERY(jsonb '[1,2]', '$' RETURNING text omit quotes); > SELECT JSON_QUERY(jsonb '[1,2]', '$' RETURNING text keep quotes); > based on v39. in ExecEvalJsonCoercion coercion->targettypmod related function calls: json_populate_type calls populate_record_field, then populate_scalar, later will eventually call InputFunctionCallSafe. so I make the following change: --- a/src/backend/executor/execExprInterp.c +++ b/src/backend/executor/execExprInterp.c @@ -4533,7 +4533,7 @@ ExecEvalJsonCoercion(ExprState *state, ExprEvalStep *= op, * deed ourselves by calling the input function, that is, after rem= oving * the quotes. */ - if (jb && JB_ROOT_IS_SCALAR(jb) && coercion->omit_quotes) + if ((jb && JB_ROOT_IS_SCALAR(jb) && coercion->omit_quotes) || coercion->targettypmod !=3D -1) now the following two return the same result: `[1,` SELECT JSON_QUERY(jsonb '[1,2]', '$' RETURNING char(3) omit quotes); SELECT JSON_QUERY(jsonb '[1,2]', '$' RETURNING char(3) keep quotes);