Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mn1I1-0000R6-3G for pgsql-general@arkaria.postgresql.org; Tue, 16 Nov 2021 16:26:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mn1I0-0008IA-2g for pgsql-general@arkaria.postgresql.org; Tue, 16 Nov 2021 16:26:32 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mn1Hy-0008I1-UM for pgsql-general@lists.postgresql.org; Tue, 16 Nov 2021 16:26:31 +0000 Received: from wout3-smtp.messagingengine.com ([64.147.123.19]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mn1Hv-0005eW-2j for pgsql-general@postgresql.org; Tue, 16 Nov 2021 16:26:30 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id F0C6232009F3; Tue, 16 Nov 2021 11:26:22 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Tue, 16 Nov 2021 11:26:23 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= message-id:date:mime-version:subject:to:references:from :in-reply-to:content-type:content-transfer-encoding; s=fm1; bh=q TyCdPD8FOKoSZLy+4BP7qv0qmdQ3iOYNZT01QtiqG0=; b=dXt111qT32bodTnwk RpiQPVC0maz27IgeuvsO9whxvvt85wDO/QPoXDP0sTvCu2tD1LWjPwINh5GZso8Q QMzoF2fDf0ID3fz42yznld5deouiO7qHPlldpnuXmKSC5vCX3Dh0C6gw3DufpDBt 0e+NH/lnU3TZEc1SPfoLWzUShBJbYQp1Vo+sUOLcx93r5oRwXUSS29sOooUij+mS CiqiozxGMTHElZAJaqHkYM9ciKfgU3XFR9ql8zgO14uDLhHFdm0HnJw66bk5u94/ Vg4/XsWe9BFRZWYkZqkIe6HnjTYPXvl5nzP0w565QXeEseAzL2r4X/+79XYBxwc0 AsfKw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=qTyCdPD8FOKoSZLy+4BP7qv0qmdQ3iOYNZT01Qtiq G0=; b=n4MtBvYr4WFOyaSZE3lLXIHSFWC3KHjUxGmv+dUfC4RK3eAB+oNYfAdjG 49sf0Js7PM4ZjwwAFYZACYpvuaPidBTTxSg0a9WzuGEcmyaAyXzkfseqXs6IqBxQ 8pfW23zgocAU/3GMpKEnEVS57nambG5KvSJ9IQAJ0/FcY1Uka8PtXfxgu9zhWK9y 9WZTe+6PQQg0MJjiOCLnr3wzBJkhCmMA5ZXmrmjLdzyejX4oy1pfIcPq+jMr6aK5 mTZWWeyxDYB9urPs4Ns03sef/UbHk4oAho6904TBDR6CfTYpgFi1uqHZm0kMliA1 sPoYyjcmDwnIjHUeIhM1urArJ1xvA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvuddrfedvgdekiecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefkffggfgfuvfhfhfgjtgfgsehtkeertddtfeejnecuhfhrohhmpeetughrihgr nhcumfhlrghvvghruceorggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomh eqnecuggftrfgrthhtvghrnhepleekgeejhfekteehfeduveetheeivdduheekudelteef vdffueehtddvgedtfeefnecuffhomhgrihhnpehpohhsthhgrhgvshhqlhdrohhrghenuc evlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrughrihgr nhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhm X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 16 Nov 2021 11:26:21 -0500 (EST) Message-ID: Date: Tue, 16 Nov 2021 08:26:21 -0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.3.1 Subject: Re: How is JSON stored in PG ? Content-Language: en-US To: David Gauthier , Postgres General References: From: Adrian Klaver In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 11/16/21 07:54, David Gauthier wrote: > Hi: > > psql (11.5, server 11.3) on linux > > I'm considering using JSON as a datatype for something I'm working on. > The reasons are... > > 1) the 'metadata' (if you want to call it that) in JSON is very > flexible.  Doesn't require an alter table or anything like that to change. > 2) The customers for this data is probably going to be python code. > IOW, they can sort things out in their code after reading the whole JSON > file/record. > 3) Nice array of built-in functions for this datatype. > 4) There does appear to be the ability to formulate query predicates on > the JSON content (just in case) > > But #4 has me a bit worried.  I'm wondering how PG stores this data > given that its content can be specified in a query predicate.  Does PG > just store the content in traditional PG tables ?  If so, I can do that > myself.  If not, is there a penalty to be paid at query time if PG needs > to get the JSON data, then dismantle into a temp table (or something > like that) to query. 1) Are you talking json or jsonb? 2) If you are going to store JSON in a non-JSON field then you will need to cast the field value to json/jsonb to use the JSON capabilities in Postgres. Not sure that is a good idea. 3) json(b) is stored in a field in a table per https://www.postgresql.org/docs/current/datatype-json.html: "The json and jsonb data types accept almost identical sets of values as input. The major practical difference is one of efficiency. The json data type stores an exact copy of the input text, which processing functions must reparse on each execution; while jsonb data is stored in a decomposed binary format that makes it slightly slower to input due to added conversion overhead, but significantly faster to process, since no reparsing is needed. jsonb also supports indexing, which can be a significant advantage." > > Pros and Cons for using JSON ? Pros You get the warm fuzzy feeling of using NoSQL in a SQL database Cons You get the task of basically unfolding a host of embedded databases. > > Thanks for any help ! > -- Adrian Klaver adrian.klaver@aklaver.com