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 1ri69U-00F77r-SO for pgsql-hackers@arkaria.postgresql.org; Thu, 07 Mar 2024 05:18:45 +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 1ri69T-000r5A-H2 for pgsql-hackers@arkaria.postgresql.org; Thu, 07 Mar 2024 05:18:44 +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 1ri69T-000r4m-6Q for pgsql-hackers@lists.postgresql.org; Thu, 07 Mar 2024 05:18:43 +0000 Received: from mail-ej1-x62e.google.com ([2a00:1450:4864:20::62e]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1ri69Q-003Ck6-I0 for pgsql-hackers@postgresql.org; Thu, 07 Mar 2024 05:18:43 +0000 Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-a4417fa396fso56342166b.1 for ; Wed, 06 Mar 2024 21:18:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709788719; x=1710393519; darn=postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=RKOSeecX0A8nSxUliGW145N5AlksxY0LdfBxnH3UgH4=; b=cY6itTAALiyRm4ziO1nAdRzuieSQDQBAgthUqo7gFnJsbqnV/332AXpeBf4ghUJf5p GWfD58m/w4yfHGJnwpTgm0MfDGL2xlJ0L2JL9QAeSnUB5zZAAevxZl12XTg4EKQmGAYS d1sDr6kfqIbzkEfbRBsswFW4a21ZBB8isL7notNQnxo4u4rIU2s6ms8g5nBpZExuI6Ms FgYhqlBnebONbrdrjJOaVivpxou4Jkwq4YqgDTgw/BuLMWtvwHx5QoffZolqdbXddGlw 5PeGo3nxySr4UpKNHq+Bl0IfwcPuCwHjsu5Y2ewdCJleeH1M+Gf2yscYCzPwK6KPK8II KtIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709788719; x=1710393519; h=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=RKOSeecX0A8nSxUliGW145N5AlksxY0LdfBxnH3UgH4=; b=UogmeWhSFCGr6wkzH7hqdF7gvATjKkkMg4ldLsh1Ke1rVh1AeqW6hM1yzoN4LSonGJ apFllNxkUdJeI10ZkJNfYW2DVSd8QrPNgAUzWr3+yZj7ineAi9Ist/j2U3juwncdfA8P r06fj5LJwByfqH8z0CQyAk4ST5k0Vmol7EliuHM6ntpBynOi2hs1Y9ym2Xu6mbN43XFw 3xW0NU++X1pwCFzdxY5Jn14D0KnO7MwydfbggsGeXqPWxBz1lIYTuE4stQ/s0l3LlMUr F6/XnFY/0BMmPY0LL9zhABbnftSAg3HmG9GdsGnHACyh1EAtPgEq537DYjydrGJT9uzq A3Gg== X-Forwarded-Encrypted: i=1; AJvYcCXpOKlwXKOp2ae+k7t1agGUQ/GEkpV65Ek9l8/H4o5dTbXzWradZsI9WMNxvRIgRGmm0CxBa1/qlcOCbw3Rg2wZzETOxO8xMsknKxG/ X-Gm-Message-State: AOJu0YwCfcbL4F0uTLyNC+Dc1i4yMioV9WHOxugBwbD8PGCyglM9axDR NrAiT8VsZOImmhfRUw3Xb58/Rj0MBxtRX09acCLbqgK0cWZab7B+6RIU1xwRG8jPAblYExlGn6P Z2vmnbHaQ+1KeIjvpG7/FiAl2MLY= X-Google-Smtp-Source: AGHT+IHgts2T3m8uyLUzsEKyZiLB+ApSLDhVPDVuXfsT9d+sVbPnn+KC+Achsmevvnbr9UC9+O4aXyJuqVCQG0VDoHg= X-Received: by 2002:a17:907:bb8d:b0:a45:b613:2b46 with SMTP id xo13-20020a170907bb8d00b00a45b6132b46mr2664146ejc.51.1709788719168; Wed, 06 Mar 2024 21:18:39 -0800 (PST) MIME-Version: 1.0 References: <1cee81f3-312f-30e3-0282-c4df7ee72f93@xs4all.nl> <202403041503.5momp6knupgo@alvherre.pgsql> <562e5ad9-1357-4752-ad28-7e56740f74f8@enterprisedb.com> In-Reply-To: <562e5ad9-1357-4752-ad28-7e56740f74f8@enterprisedb.com> From: Himanshu Upadhyaya Date: Thu, 7 Mar 2024 10:48:02 +0530 Message-ID: Subject: Re: remaining sql/json patches To: Tomas Vondra Cc: Amit Langote , Alvaro Herrera , Erik Rijkers , jian he , Andres Freund , Andrew Dunstan , PostgreSQL-development Content-Type: multipart/alternative; boundary="0000000000003f424606130b35d4" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000003f424606130b35d4 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Mar 6, 2024 at 9:04=E2=80=AFPM Tomas Vondra wrote: > > > I'm pretty sure this is the correct & expected behavior. The second > query treats the value as string (because that's what should happen for > values in double quotes). > > ok, Then why does the below query provide the correct conversion, even i= f we enclose that in double quotes? =E2=80=98postgres[102531]=3D#=E2=80=99SELECT * FROM JSON_TABLE(jsonb '{ "id" : "1234567890", "FULL_NAME" : "JOHN DOE"}', '$' COLUMNS( name varchar(20) PATH 'lax $.FULL_NAME', id int PATH 'lax $.id' ) ) ; name | id ----------+------------ JOHN DOE | 1234567890 (1 row) and for bigger input(string) it will leave as empty as below. =E2=80=98postgres[102531]=3D#=E2=80=99SELECT * FROM JSON_TABLE(jsonb '{ "id" : "12345678901", "FULL_NAME" : "JOHN DOE"}', '$' COLUMNS( name varchar(20) PATH 'lax $.FULL_NAME', id int PATH 'lax $.id' ) ) ; name | id ----------+---- JOHN DOE | (1 row) seems it is not something to do with data enclosed in double quotes but somehow related with internal casting it to integer and I think in case of bigger input it is not able to cast it to integer(as defined under COLUMNS as id int PATH 'lax $.id') =E2=80=98postgres[102531]=3D#=E2=80=99SELECT * FROM JSON_TABLE(jsonb '{ "id" : "12345678901", "FULL_NAME" : "JOHN DOE"}', '$' COLUMNS( name varchar(20) PATH 'lax $.FULL_NAME', id int PATH 'lax $.id' ) ) ; name | id ----------+---- JOHN DOE | (1 row) ) if it is not able to represent it to integer because of bigger input, it should error out with a similar error message instead of leaving it empty. Thoughts? --=20 Regards, Himanshu Upadhyaya EnterpriseDB: http://www.enterprisedb.com --0000000000003f424606130b35d4 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
On Wed, Mar 6, 2024 at 9:04=E2=80=AFP= M Tomas Vondra <tomas.v= ondra@enterprisedb.com> wrote:


I'm pretty sure this is the correct & expected behavior. The second=
query treats the value as string (because that's what should happen for=
values in double quotes).

=C2=A0ok, Then why does the below=C2=A0query provide = the correct conversion, even if we enclose=C2=A0that in double quotes?
=E2=80=98postgres[102531]=3D#=E2=80=99SELECT * FROM JSON_TABLE(jsonb = '{
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0"id" : "12345678= 90",
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0"FULL_NAME" : &quo= t;JOHN DOE"}',
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 '$'
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 COLUMNS(
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0name varchar(20) PATH 'lax $.FULL_NAME',
=C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0id in= t PATH 'lax $.id'
=C2=A0 =C2=A0 =C2=A0 )
=C2=A0 =C2=A0)
;<= br>
=C2=A0 =C2=A0name =C2=A0 | =C2=A0 =C2=A0 id =C2=A0 =C2=A0 ----------+------------
=C2=A0JOHN DOE | 1234567890
(1 row)

and for bigger input(string) it will leave as e= mpty as below.
=E2=80=98postgres[102531]=3D#=E2=80=99SELECT * FRO= M JSON_TABLE(jsonb '{
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0"id&quo= t; : "12345678901",
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0"FU= LL_NAME" : "JOHN DOE"}',
=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 '$'
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 COLUMNS(
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0name varchar(20) PATH 'lax $.FULL= _NAME',
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0id int PATH 'lax $.id'
=C2=A0 =C2=A0 =C2=A0 )=C2=A0 =C2=A0)
;
=C2=A0 =C2=A0name =C2=A0 | id
----------+----<= br>=C2=A0JOHN DOE | =C2=A0
(1 row)

seems i= t is not something to do with data enclosed in double quotes but somehow re= lated with internal casting it to integer and I think in case of bigger inp= ut it is not able to cast it to integer(as defined under COLUMNS as id int = PATH 'lax $.id')=C2=A0

=E2=80=98postgres[1= 02531]=3D#=E2=80=99SELECT * FROM JSON_TABLE(jsonb '{
=C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0"id" : "12345678901",
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0"FULL_NAME" : "JOHN DOE"}= 9;,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 '$'<= br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 COLUMNS(
=C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0na= me varchar(20) PATH 'lax $.FULL_NAME',
=C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0id int PATH 'lax $.= id'
=C2=A0 =C2=A0 =C2=A0 )
=C2=A0 =C2=A0)
;
=C2=A0 =C2=A0na= me =C2=A0 | id
----------+----
=C2=A0JOHN DOE | =C2=A0
(1 row)
)

if it is not able to represent it to inte= ger because of bigger input, it should error out with a similar error messa= ge instead of leaving it empty.

Thoughts?

--
Regards,
Himanshu Upadhyaya
EnterpriseDB: http://www.enterprisedb.com
--0000000000003f424606130b35d4--