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 1tFtpi-00HFyw-P0 for pgsql-general@arkaria.postgresql.org; Tue, 26 Nov 2024 11:34:18 +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 1tFtph-006IMA-Fb for pgsql-general@arkaria.postgresql.org; Tue, 26 Nov 2024 11:34:17 +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 1tFtph-006ILk-3w for pgsql-general@lists.postgresql.org; Tue, 26 Nov 2024 11:34:17 +0000 Received: from mail-qv1-xf30.google.com ([2607:f8b0:4864:20::f30]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1tFtpe-003yGj-8t for pgsql-general@lists.postgresql.org; Tue, 26 Nov 2024 11:34:15 +0000 Received: by mail-qv1-xf30.google.com with SMTP id 6a1803df08f44-6d41864d745so34100566d6.2 for ; Tue, 26 Nov 2024 03:34:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gotab.io; s=google; t=1732620852; x=1733225652; darn=lists.postgresql.org; h=mime-version:subject:message-id:to:from:date:from:to:cc:subject :date:message-id:reply-to; bh=mP4uX+GH/mOJPycGifviIPK1pk0q9bzgKbmDZewSSGs=; b=aGroKHz1Lk1sS8lkpFFr5Rx1HcjdUn6k9k6xPziphXUrj92GT62F1MdEVyQMEkkCmB sF6dIFa4q+FDnvqRw/V/C+roWelLLYxWyN6+77NoUKAi5NvlyWSOC4ehuiu8GzA/ps2/ ZBtJE4w+jVN9akAZmNoZp+wHGGgeZaHsNBsJcCM6XtFN8wIm+xRZbUY3apvQDrQ4UD6I sk/+HXHK7S5ADmbdwhmvISvo+SopbV3Wxiibwj3pB1EeMEQjuoQB9LfHNUdYbNcUMVfy gLnLFi5Qdn6rrF2t8vfM4vvNAbcd50MKvF+qh9m0GYdo7AA2Yby8OO2GYPD+z8ggsloq fkoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732620852; x=1733225652; h=mime-version:subject:message-id:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=mP4uX+GH/mOJPycGifviIPK1pk0q9bzgKbmDZewSSGs=; b=HxeziqLpgC9OhJecsM2PMpeBJ3a9oiXlbwi14BIyMqSqOCm577XIhmgxAoIm2YzUlB wb/aisLAUBvLLi+CzXS/7+nqfX7wjelLwCC38epo7eoBGDuc+eKmWQXPWJ4ZFvkuEMlo wwVwpd26Qjr4h9w/3NEISh6D2oPq6o4NOCgIRyLEOWjrW2YyYaEv8CQT4xRtx6PBe99Q kvEOVHWhg/PdHEOXZ+sfGT8+g8FPBxOCrKcZqRredIBGCqGmMBFFUojgEVc7Z/DAv5DY Lu3bx21QKI3yHpBjOkxttoOGrFUBM+H6DS6DMk1gm0YRxv+gFOlTfMsbfNz/UCRQNnK/ V9KQ== X-Gm-Message-State: AOJu0YxQu7A/pGlV5h5AV1LKK4/k41z9eY3NkClDiuey6cW3bUcKOfmZ 1teqB9B/qPvAO9Nk7OKzwa1vcrcnub7j9CUTtZL7bP+InbyJ1ZsMFIzHxiw1PlFPJ1MTYalEGXZ w X-Gm-Gg: ASbGnctwSlXlp712ChgFwOkuWv2QmCbBKd7crLf3PtSVbsm3yRKpxL4GZ7J0C27DKBp L/j3uw1g3mpmU1zyzH37r3XNVp2NYWN066LnkUcbD/0CFU8+KJLXbJSDLVE0naD2wqIFa0kxQay 2qLvikJIj2DE/x/MlZTxORGdoGbGHoRgC5FtNZXW6qdICVcE2KWBx9S++gCid9fP47Y6sEMz1ha cruufU5UXMHw545iOGI3zmbvIy0CCJ51ltFYGLO4/4InJovOkEtLIPU2jlPwQ2UXQwBmSeA1+Vn C6iNapOXCmAq5tK+LI2DoFIIkbI= X-Google-Smtp-Source: AGHT+IHMaKaonqZH4++BMENUzMWDjWUwWGWGWHh2Ain/uzt7Ls5GOi5RaMvNAVFP+rGNm5oRaA6v+Q== X-Received: by 2002:a05:6214:29c1:b0:6d4:f77:613c with SMTP id 6a1803df08f44-6d450e989f6mr311948196d6.25.1732620852288; Tue, 26 Nov 2024 03:34:12 -0800 (PST) Received: from [192.168.1.223] (pool-71-114-82-244.washdc.fios.verizon.net. [71.114.82.244]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d451a82fe3sm54538916d6.3.2024.11.26.03.34.11 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Nov 2024 03:34:11 -0800 (PST) Date: Tue, 26 Nov 2024 06:34:06 -0500 From: Tim McLaughlin To: pgsql-general@lists.postgresql.org Message-ID: <536dca0f-ef1a-4621-ac1f-9c1c1dd74fbd@Spark> Subject: change JSON serialization for BIGINT? X-Readdle-Message-ID: 536dca0f-ef1a-4621-ac1f-9c1c1dd74fbd@Spark MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="6745b233_4f4ef005_1066" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --6745b233_4f4ef005_1066 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline 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 I tried doing this, but it has no effect: CREATE or replace =46UNCTION bigintJson(bigint) RETURNS json =C2=A0=C2=A0 =C2=A0AS 'select =241::text::json;' =C2=A0=C2=A0 =C2=A0LANGUAGE SQL IMMUTABLE RETURNS NULL ON NULL INPUT; create cast (bigint as json) with function bigintJson(bigint) as implicit= ; Thanks for any guidance. -- Tim McLaughlin --6745b233_4f4ef005_1066 Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline
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

I tried doing this, but it has no effect:

CREATE or replace =46UNCTION bigintJson(bigint) RETURNS json
&=23160;&=23160; &=23160;AS 'select =241::text::json;'
&=23160;&=23160; &=23160;LANGUAGE SQL IMMUTABLE RETURNS NULL ON NULL INPU= T;

create cast (bigint as json) with function bigintJson(bigint) as implicit= ;

Thanks for any guidance.

--
Tim McLaughlin
--6745b233_4f4ef005_1066--