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 1riBgY-00FbrU-Og for pgsql-hackers@arkaria.postgresql.org; Thu, 07 Mar 2024 11:13:15 +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 1riBgW-004aRX-6F for pgsql-hackers@arkaria.postgresql.org; Thu, 07 Mar 2024 11:13:12 +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 1riBgV-004aRP-SA for pgsql-hackers@lists.postgresql.org; Thu, 07 Mar 2024 11:13:12 +0000 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1riBgP-003IbS-Dj for pgsql-hackers@postgresql.org; Thu, 07 Mar 2024 11:13:10 +0000 Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-412f55695d1so6922815e9.0 for ; Thu, 07 Mar 2024 03:13:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; t=1709809985; x=1710414785; darn=postgresql.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=kjV5xHK06lE/1AtCyWxZTScxy5jh8d8GeUEFV8B8gHU=; b=SsqTKBr9hyyCQa6N8qOU1jIm4rgs9/f5eQLiR9GF04wLBktK6O6bJIbYzxPUUZIBnn clvtjH3PqkBMm6auzodTb4XTdMvINVZIDvuXUSpS7Gx/QMpbvlj36qw+2QYxCsEcE5SJ MyxBMYRSz/tFbOO2ZIE63qD3twCSoq6FbocdzjUYbu8HqGNUPD8UZNlgSHbLzIeC0BTy KITH8qEqcLVrSAgqS/8MzY6NsqxhSRWG+Fj5M2EUTDOx6ebNXQwOXsfS9TSkM6Xrm+d/ GnNVoKx0t7gzEaNsVjmOg5M6kmXZOlY5dkbjcVpaCr+ivorDH4JKV5SjkiRDKaTlPZTG c34w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709809985; x=1710414785; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=kjV5xHK06lE/1AtCyWxZTScxy5jh8d8GeUEFV8B8gHU=; b=Sj+DTcB15MtxBaZ3IHnRwey6kzXY1KfTaESla22Zpm3QIaIok5B8C+iJcYoI4vkIu6 uybBbt8OsvZG7hXxvojZnHwImvPYbbs1uakd/awss4j961QYRmQQa5ZJmO8MMoeOLNTm CQnoAkqLTglse7hoKq/Z8wPIn/k8hYdeoO04CQ/3GM1ZQjgGmJKWfSXIqGLzac8GHDIN im2AKrdmkqznoPlC2ereINXri37zzZ0RCIFavzuO+OKvMuOCDXmJS64xawz9IajOFiRk m7PXE6u0DYtjlpL2VP76rP92W8yKjPNrWZ+ilxsfGY/F8253OhR/dVmudVJsmmc73UYx bdxQ== X-Forwarded-Encrypted: i=1; AJvYcCV6RO8N3WG5ZqfZqVMNu9P3siSwiPJdJHey/+GTvOqigwVjHH4Md8Kh8TUSN0pM/2g2a089FNCvJysxcWWVserDrW3GBP4gs+aspR/G X-Gm-Message-State: AOJu0YxyjU5bXqZFvg8KM97C0vZLgFNU2iUVvtxeall5e9RluKrPkyxT +Jh9bqPU/HjLLTv/5rqE0IY6pEB8tgZxbM8OJVBMPLPGrFvjJBO/qUKThxEwYw== X-Google-Smtp-Source: AGHT+IGM4BWVhFVDRlbxFPELeyxUsdYM1P4PCtpQAukHulAsT3XA0D/v/jhpq11mATwbZ80K1Btb0A== X-Received: by 2002:a05:600c:3481:b0:412:f809:9957 with SMTP id a1-20020a05600c348100b00412f8099957mr2720398wmq.12.1709809984936; Thu, 07 Mar 2024 03:13:04 -0800 (PST) Received: from [10.137.0.18] (ip-86-49-229-30.bb.vodafone.cz. [86.49.229.30]) by smtp.gmail.com with ESMTPSA id fs23-20020a05600c3f9700b00412f195426dsm2274000wmb.15.2024.03.07.03.13.04 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 07 Mar 2024 03:13:04 -0800 (PST) Message-ID: Date: Thu, 7 Mar 2024 12:13:03 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: remaining sql/json patches Content-Language: en-US To: Himanshu Upadhyaya Cc: Amit Langote , Alvaro Herrera , Erik Rijkers , jian he , Andres Freund , Andrew Dunstan , PostgreSQL-development References: <1cee81f3-312f-30e3-0282-c4df7ee72f93@xs4all.nl> <202403041503.5momp6knupgo@alvherre.pgsql> <562e5ad9-1357-4752-ad28-7e56740f74f8@enterprisedb.com> From: Tomas Vondra In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 3/7/24 06:18, Himanshu Upadhyaya wrote: > On Wed, Mar 6, 2024 at 9:04 PM 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 if > we enclose that in double quotes? > ‘postgres[102531]=#’SELECT * 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. > ‘postgres[102531]=#’SELECT * 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') > > ‘postgres[102531]=#’SELECT * 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? > Ah, I see! Yes, that's a bit weird. Put slightly differently: test=# SELECT * FROM JSON_TABLE(jsonb '{"id" : "2000000000"}', '$' COLUMNS(id int PATH '$.id')); id ------------ 2000000000 (1 row) Time: 0.248 ms test=# SELECT * FROM JSON_TABLE(jsonb '{"id" : "3000000000"}', '$' COLUMNS(id int PATH '$.id')); id ---- (1 row) Clearly, when converting the string literal into int value, there's some sort of error handling that realizes 3B overflows, and returns NULL instead. I'm not sure if this is intentional. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company