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 1mnNGv-0007Gc-U2 for pgsql-general@arkaria.postgresql.org; Wed, 17 Nov 2021 15:54:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mnNGu-0001Pn-Jd for pgsql-general@arkaria.postgresql.org; Wed, 17 Nov 2021 15:54:52 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mnNGu-0001Pd-9I for pgsql-general@lists.postgresql.org; Wed, 17 Nov 2021 15:54:52 +0000 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mnNGr-0004Mq-OT for pgsql-general@postgresql.org; Wed, 17 Nov 2021 15:54:51 +0000 Received: by mail-wr1-x42c.google.com with SMTP id u18so5603246wrg.5 for ; Wed, 17 Nov 2021 07:54:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20210112.gappssmtp.com; s=20210112; h=message-id:subject:from:to:date:in-reply-to:references:user-agent :mime-version:content-transfer-encoding; bh=islA6EV0pwgw392A5x9Hav2UMbQVkwIh2XAjU37rhuU=; b=30gngix6pikKPCzg2JmliTb6gMBkpmD/vl0OGpWqXdgzJ4EfNMQIwZwnUOvXCyBhBY ZAqjfEDvPkvogiUD1qEYD/jVq3wTJr63dGFkMB1PZUKycOzxDwuPn4XdYkg/hxt853vP 3MYUNAdvsaprWWa6Ot6RD+8dDN3XV8/v9iqJeu8UdlzdVM4JPNMY8K+IOYjBvsHA4XIe MvBv+/rkgz+ipjn7xcfFECrNV7kMPqZaUYnsXvZR0QacqCeLjvWwJBXVtw7ikI72XOz5 gM/v4uQ6fXU56w/Ov/Xo9rJKmAE53nN5WcWIP9rvjwhJt5jd+y41E55rdQUG6hDU4ve8 z9Ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:subject:from:to:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=islA6EV0pwgw392A5x9Hav2UMbQVkwIh2XAjU37rhuU=; b=ICKMEOdUwKI8cmmstacqi1ClSlfehHN1kS2/Zxyd6jmeWKEc/wh1841SZJ5/NtJ/HO cBYoYKyBJZS7MgTiBbdkf4EMUo2QN7mIRjrPecrERavAXqoDspOEGW3D6B1mHQ2NrLTl NHHLJnQSSpavq6wiIe/xLoBqBTEoKYAh4An5wXrxeJpPpBaJbdNHgHWXxx/siqcdUnvD UCPmKAt+CmnMxhJHYyBZDH+PWucEwXbiMUm8CoJmkzYl6ZezvgMehV/oRFHxelUbQP9A 8PeX1iakxh6ZAUXerrIXYrDdIq1viIPeP60/VvzDOpDVUh6jCnK/XL0PxMgF7PapYrdN aNCA== X-Gm-Message-State: AOAM530fOW60EtdRrX8lNPI8bCDF7IZFAXeXctw1lqxr5We/LF9SOS1Z C2iyHx1kxf4F6gLFhbs56sA7/Q== X-Google-Smtp-Source: ABdhPJynwVe3d4QRDCjhIKiI0yHyaGiWDdDGj1ocn+qjfDOdPL0j+glDh6NJ0cd+yo3a1W0o8O4bRg== X-Received: by 2002:a5d:5244:: with SMTP id k4mr21979478wrc.77.1637164488202; Wed, 17 Nov 2021 07:54:48 -0800 (PST) Received: from localhost.localdomain (62-46-250-24.adsl.highway.telekom.at. [62.46.250.24]) by smtp.gmail.com with ESMTPSA id y12sm246386wrn.73.2021.11.17.07.54.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Nov 2021 07:54:47 -0800 (PST) Message-ID: <88ceafed7aa3075da85be4fc66306ac442081111.camel@cybertec.at> Subject: Re: How is JSON stored in PG ? From: Laurenz Albe To: David Gauthier , Postgres General Date: Wed, 17 Nov 2021 16:54:47 +0100 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.40.4 (3.40.4-2.fc34) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, 2021-11-16 at 10:54 -0500, 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. I don't follow. There are JSON functions and operators you can use, and then there is the very powerful JSONPATH query language. > 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. Yes, it is stored in tables. But "jsonb" is stored in a binary data structure that makes it fast and efficient to access attributes and values. I have written up the indications and counter-indications for using JSON here: https://www.cybertec-postgresql.com/en/json-postgresql-how-to-use-it-right/ Yours, Laurenz Albe -- Cybertec | https://www.cybertec-postgresql.com