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 1rSyJi-00H72H-KW for pgsql-hackers@arkaria.postgresql.org; Thu, 25 Jan 2024 11:54:47 +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 1rSyJh-00G8YS-PW for pgsql-hackers@arkaria.postgresql.org; Thu, 25 Jan 2024 11:54:45 +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 1rSyJh-00G8YI-Fu for pgsql-hackers@lists.postgresql.org; Thu, 25 Jan 2024 11:54:45 +0000 Received: from mail-ot1-x32d.google.com ([2607:f8b0:4864:20::32d]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rSyJe-003IQR-Q8 for pgsql-hackers@postgresql.org; Thu, 25 Jan 2024 11:54:44 +0000 Received: by mail-ot1-x32d.google.com with SMTP id 46e09a7af769-6dddb927d02so3939771a34.2 for ; Thu, 25 Jan 2024 03:54:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706183682; x=1706788482; 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=Lo5dowrX0w4+aGGGYo0XTea6ixHiBQal+Z3kIBnu92Q=; b=hH9f2ZfRXXFcI2cSKOX8Sr5VHxm7iyh/5qw4EB1Pll0uQDOD5dgv+vvupv6DZhRW7g bcB2F+KlHuekYNq+ThM7U2tCpfh1/zlqjVYtl0qXnl9xwFrfZhNSMAW6KOxkUs+YTe/y GA6dhqmbdFzrF4PMwKFUqhiUbR6PUe+fUyMOz/y0dr0gP9JQaoTBBwudH4OV6tGOiPad xJFEwQhOPGGNtvOQxL19Mm4ZIT/cp4IKj92GUvoZLwybEdl1rJLXNbrNwoh3uWgzBkdz QlpGAbmf+Yyabj7njrx0hI5w6jJowKd8xWsyyHjjTfqdskSjHr41pXSfqMKdw9xsQ+80 uBaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706183682; x=1706788482; 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=Lo5dowrX0w4+aGGGYo0XTea6ixHiBQal+Z3kIBnu92Q=; b=QOVyv/uYXrqzyohXAnJFbNMm3k0wTrgDmmONZMD/HVs6coSwTxeR8uQ66HLc8ttwse xy2Y0lAAGUXLRj2T79pmG9bTUkDVS4DVqhLsNG6V45mXB2ud8Kgybncdg9JHeeMMk5nx dK+4iuW6Duna02EU3GnwUGNUJxldwzfKQszdGTiHmMRHF2uhDsLBFlsaQAhGrTWrT49b EEMa4i1t+HXAVVZLAkhHV/SuxJnSH5yu34I06QbZR++I4gYoYjt3Uzb+6FEzvxZtSFb8 11iOvktdNcw8XCughOKqmcYmW9i8qO/aXZudin6WIBof/Uc9uHFI0uQlCkshwlBQoTFo dNwg== X-Gm-Message-State: AOJu0YxmDQT1/ujsz/NAywx6WulrdPK9UqbXBMMFxKOWj/4PHArTrDeU 0/eAWheoJ2d5j+JOuFt+UDiKKqZ765/1ksfrxm1oje0/RMNd82vWUhXSyzaw66Wm1AAOrXxbB6D nRTkr4YFkGybghV7Qh9LURUsJ1Mw= X-Google-Smtp-Source: AGHT+IGXOlU7cvClShzsnn4imujF8rHJDAVQU+VuHQyUqpXDsAN3uTYsjdMbGP/q8k1L0LRJM4Nb4i+WbdA4Nh11W8Y= X-Received: by 2002:a05:6830:124e:b0:6dd:ef07:9db3 with SMTP id s14-20020a056830124e00b006ddef079db3mr842454otp.49.1706183682172; Thu, 25 Jan 2024 03:54:42 -0800 (PST) MIME-Version: 1.0 References: <202401181711.qxjxpnl3ohnw@alvherre.pgsql> <202401221619.ragf2vnbyopl@alvherre.pgsql> In-Reply-To: From: Amit Langote Date: Thu, 25 Jan 2024 20:54:25 +0900 Message-ID: Subject: Re: remaining sql/json patches To: Alvaro Herrera Cc: Andres Freund , Erik Rijkers , jian he , 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 6:09=E2=80=AFPM Amit Langote wrote: > On Wed, Jan 24, 2024 at 10:11=E2=80=AFPM Amit Langote wrote: > > I still need to take a look at your other report regarding typmod but > > I'm out of energy today. > > The attached updated patch should address one of the concerns -- > JSON_QUERY() should now work appropriately with RETURNING type with > typmod whether or OMIT QUOTES is specified. > > But I wasn't able to address the problems with RETURNING > record_type_with_typmod, that is, the following example you shared > upthread: > > create domain char3_domain_not_null as char(3) NOT NULL; > create domain hello as text not null check (value =3D 'hello'); > create domain int42 as int check (value =3D 42); > create type comp_domain_with_typmod AS (a char3_domain_not_null, b int42)= ; > select json_value(jsonb'{"rec": "(abcd,42)"}', '$.rec' returning > comp_domain_with_typmod); > json_value > ------------ > > (1 row) > > select json_value(jsonb'{"rec": "(abcd,42)"}', '$.rec' returning > comp_domain_with_typmod error on error); > ERROR: value too long for type character(3) > > select json_value(jsonb'{"rec": "abcd"}', '$.rec' returning > char3_domain_not_null error on error); > json_value > ------------ > abc > (1 row) > > 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. --=20 Thanks, Amit Langote EDB: http://www.enterprisedb.com