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 1tFvHx-00HOrl-QC for pgsql-general@arkaria.postgresql.org; Tue, 26 Nov 2024 13:07:34 +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 1tFvHv-006jNz-U6 for pgsql-general@arkaria.postgresql.org; Tue, 26 Nov 2024 13:07:31 +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 1tFvHv-006jNJ-Gr for pgsql-general@lists.postgresql.org; Tue, 26 Nov 2024 13:07:31 +0000 Received: from mail-yw1-x1130.google.com ([2607:f8b0:4864:20::1130]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1tFvHr-0048Ti-Js for pgsql-general@lists.postgresql.org; Tue, 26 Nov 2024 13:07:30 +0000 Received: by mail-yw1-x1130.google.com with SMTP id 00721157ae682-6eeac3535baso54893177b3.1 for ; Tue, 26 Nov 2024 05:07:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gotab.io; s=google; t=1732626445; x=1733231245; darn=lists.postgresql.org; h=mime-version:subject:references:in-reply-to:message-id:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to; bh=ab4clyU0FNoc7ED3lTcoJ5gs9l73CFzzY7VNDJSyIl8=; b=YzQnj5heJ9xhyDos3TMhZOexVdFjFzTChiYOgtxLDceeRPzItCt6nz2brflwAlMtmJ 7zthxClTmbKx2v4wy3M5T9iWioF1ttJjQn5aEHgXrE+fhJEZEBHlDxoHnBupnwkzkgX+ DRwwGKjXIClVW/YVQhu8UjWoZLpkRS6c6MseWieOf/2aLKs+iKxRps8REowxmSo+7qIG qr5pmsNyTYZ9YaUmsWWB9Ik6b0dFOEJ6BBNL5J4rc6i09BAM0CY7ZMYkSdgNFmvOvQgA tyMYBjJ9aQ94ho4TFem/9xqOmUAgxl+dOWSzpDbqw+Va+qIYmJWtuBa8HviOVN2efgHa Dehg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732626445; x=1733231245; h=mime-version:subject:references:in-reply-to:message-id:cc:to:from :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ab4clyU0FNoc7ED3lTcoJ5gs9l73CFzzY7VNDJSyIl8=; b=NfJcjfNpurJn4IuX2vQK8SxAJo/S+KiFnFgp32YKsyGD1P2lDPBEdS2BCZIqd77FIY gxQTKSvfN68jDhnvFvn8Vpik4Tf7UHfhNDqzLmkMZCgxoFVNJmjP5TYwjLsy7i31mwxs YNR4SJsH6zuRAodSX04fus4633hOYh5WE4hxtYrS9PqkXZpbZYtUECG4cpwdc9ilqVJj d7knGP+d1iVpg7EaoauiPir+1nypXce2bHjVoZzaRoBy8W2xFHCnVqHXZ5HTWzOfZObj jVl1x7uA6D9rZ//9UCzwLWDJd4DGNtj84rxNBjzQK76UANiQlSqDYo5GCzNSBpivod3E FlKg== X-Gm-Message-State: AOJu0YwVcqqyimLtoZsQz2MvMLSqQij7fbdUHObnXLjjcdVhvSrPP1zm y9rXb+GvtBhWKhgCfMOVEjuQlhl0cJRvTGQutDueyPzAidZmp0U2y/ivYoRLCVQ= X-Gm-Gg: ASbGncvabVOYhWdHyiVV/PseOWAjGzg1Y/Au7QZ2Ndf/szBTLZRypxU2MmWWas7+K9G TS94kxDg0YFl6mtCr0ytaRvMiPhVyfznH8MV/RxNGTt9IP2Y0MT4O4IK2oiGaC2As5D7ZMdZSte AikAmn1b0rafwVf6x/6S5A3ZiRlNpLK4AW1AHGMMSKWaC4xnV9qEQcOefKAR2jFOefG+1p5FJw7 7XqcvEUn9CjBm4cpiPUrNrF+3yfoJ6JqySBKLHt24lEIaXC/S6WqziorCaergtnx6OAVoqDohWO o+URlV6HPH7RSg== X-Google-Smtp-Source: AGHT+IFK9j3rgl9Qriy9tUXRPKvNg9wqmQEOHNVsHi1tsct/e+DxACKdEQoeEyuclhQ6yz8u88JUHA== X-Received: by 2002:a05:690c:7091:b0:6e7:f98e:12dc with SMTP id 00721157ae682-6eee08a970bmr149946647b3.9.1732626445479; Tue, 26 Nov 2024 05:07:25 -0800 (PST) Received: from [2600:382:791a:957d:e070:a86f::] ([2600:382:791a:957d:d50a:7bd5:5d66:bd76]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6eee009614fsm22664377b3.109.2024.11.26.05.07.23 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Nov 2024 05:07:24 -0800 (PST) Date: Tue, 26 Nov 2024 08:07:13 -0500 From: Tim McLaughlin To: Victor Yegorov Cc: pgsql-general@lists.postgresql.org Message-ID: In-Reply-To: References: <536dca0f-ef1a-4621-ac1f-9c1c1dd74fbd@Spark> Subject: Re: change JSON serialization for BIGINT? X-Readdle-Message-ID: e5d6c428-a9a7-438d-a573-b0afd03649c0@Spark MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="6745c80a_5dc79ea8_1066" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --6745c80a_5dc79ea8_1066 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Thanks for the idea.=C2=A0=C2=A0We could do that, but that would require = code changes to our thousands of lines of SQL that generate JSON to add t= he explicit cast to text.=C2=A0=C2=A0I am hoping not to have to do that. There are numerous places where I would think this would be useful: BIGINT or NUMERIC overflows Javascript Number Max Integer (my problem) wi= th the default JSON parser in NodeJS DECIMAL / NUMERIC value loses precision due to being ingest as a JSON Num= ber which is annotated in high precision using a standard JSON parser There are probably others, but the point is that there are cases where it= would be great to override the default JSON serialization of Postgres sc= alars rather than have to go explicitly cast them all to text first. -- Tim McLaughlin On Nov 26, 2024 at 6:36=E2=80=AFAM -0500, Victor Yegorov , wrote: > =D0=B2=D1=82, 26 =D0=BD=D0=BE=D1=8F=D0=B1. 2024=E2=80=AF=D0=B3. =D0=B2 = 14:34, Tim McLaughlin : > > > Is there a way to have Postgres serialize BIGINT as a string rather= than number in JSON=3F=C2=A0=C2=A0By default it does this: > > > > > > > > > select row=5Fto=5Fjson(row(500::bigint)); > > > =C2=A0row=5Fto=5Fjson > > > ------------- > > > =C2=A0=7B=22f1=22:500=7D > > > > > > But I want it to do this (note that =22500=22 is quoted): > > > > > > select row=5Fto=5Fjson(row(500::bigint)); > > > =C2=A0row=5Fto=5Fjson > > > ------------- > > > =C2=A0=7B=22f1=22:=22500=22=7D > > Will this work=3F > > select row=5Fto=5Fjson(row(500::text)); > > -- > Victor Yegorov --6745c80a_5dc79ea8_1066 Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline
Thanks for the idea.&=23160;&=23160;We could do tha= t, but that would require code changes to our thousands of lines of SQL t= hat generate JSON to add the explicit cast to text.&=23160;&=23160;I am h= oping not to have to do that.

There are numerous places where I would think this would be useful:
= BIGINT or NUMERIC overflows Javascript Number Max Integer (my problem) wi= th the default JSON parser in NodeJS
DECIMAL / NUMERIC value loses precision due to being ingest as a JSON Num= ber which is annotated in high precision using a standard JSON parser

There are probably others, but the point is that there are cases where it= would be great to override the default JSON serialization of Postgres sc= alars rather than have to go explicitly cast them all to text first.

--
Tim McLaughlin
On Nov 26, 2024 at 6:36=E2=80=AFAM = -0500, Victor Yegorov <vyegorov=40gmail.com>, wrote:
=D0=B2=D1=82, 26 =D0=BD=D0=BE=D1=8F=D0=B1. 2024=E2=80= =AF=D0=B3. =D0=B2 14:34, Tim McLaughlin <tim=40gotab.io>:
Is there a way to have Postgres serialize BIGINT as= a string rather than number in JSON=3F&=23160;&=23160;By default it does= this:


select row=5Fto=5Fjson(row(500::bigint));
&=23160;row=5Fto=5Fjson&=23160;
-------------
&=23160;=7B=22f1=22:500=7D

But I want it to do this (note that =22500=22 is quoted):

select row=5Fto=5Fjson(row(500::bigint));
&=23160;row=5Fto=5Fjson&=23160;
-------------
&=23160;=7B=22f1=22:=22500=22=7D

Will this work=3F

select row=5Fto=5Fjson(row(500::text));

--
Victor Yegorov
--6745c80a_5dc79ea8_1066--