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 1nbb4A-0002pX-Nq for pgsql-general@arkaria.postgresql.org; Tue, 05 Apr 2022 04:45:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nbb48-0005Rp-CL for pgsql-general@arkaria.postgresql.org; Tue, 05 Apr 2022 04:45:16 +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 1nbb47-0005Rf-W6 for pgsql-general@lists.postgresql.org; Tue, 05 Apr 2022 04:45:16 +0000 Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nbb42-0005uH-PB for pgsql-general@lists.postgresql.org; Tue, 05 Apr 2022 04:45:15 +0000 Received: by mail-pf1-x432.google.com with SMTP id y10so11000487pfa.7 for ; Mon, 04 Apr 2022 21:45:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:message-id:subject:mime-version; bh=Onr1BWyn7Kqdz4Oxv3NXn7mo26DrpPAA/Hc6hM9zFtE=; b=R/2rVNCAqnoyqx1/ObbUr/iXueQ4cGIL7z3DfffTv1C7GpV7svrWp+IrK/gbSlsacL +RcrG0uvtuXA3fLdqaK3yNq195iZ1rlT583aTdTAHCoeoNRUUH/e7P8kFrsNfN/HSOh7 HD8qhUeoDVCheI/OQys9ur1GOP96rPb8u91EIiZB13zfpJ0p5ZtYmd1MGaTNZ6BY4EbY RDCQvNUGoqijd1bki7G7iz8S5C3fLUVOfYWOrKqy4gRgSF3robG7k6gcruHMikWdY9jD B6lVgU161GCmQRLm4kjGr4HTS0dp1AV1M/MyGavAFz8Xp4SD1YGP+0atoG5C3L9ClxeQ AN6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:message-id:subject:mime-version; bh=Onr1BWyn7Kqdz4Oxv3NXn7mo26DrpPAA/Hc6hM9zFtE=; b=tjLRFcBdRKjEzsSIFeVSnfXS8mrlhGFkTxIypwcnQ3XtrlXS7Wv0/T/GNvBdb9vLfS 7MtX6q7Hb8jF+j3mjfqjiW7L48IdbR+afz+rZEOTAwPjtrH/mKXjCTI6M5UUiYwx36OV CLTJNVvepX+11oBcWDcCH1rGiHPjfIcDaWBQQ0NoKo2phydH2pXmZccixDHTL3Hun7q+ +gqwlQ+k7ZKtcO5YLP7J8Gex7zbBupyiT7fI2mHiI0LL0wTXdUOf6C+ynDMROD3bp/+i ulf7qOkxVYs2XAG4isqiDDwPeIju2PPNHOzLFli2Ou85oxgdqa5bkGRwKKYNQkBI+vhp uLkw== X-Gm-Message-State: AOAM5307nr7bXrwL/s8iD7Z0dvsSC2gVNE0FVMG7l/VpIIlfgHuLGTlK R+HltmH/+K6JN9x0RzQWWccXCPhdByI= X-Google-Smtp-Source: ABdhPJyqwen0y9GRsUOYp0O5GWfvroDC2u+8EyldlYOdF0+OOt/4BF1lvLWaOn46+74qt22N6vvgYQ== X-Received: by 2002:a05:6a00:e0b:b0:4fa:a167:5b35 with SMTP id bq11-20020a056a000e0b00b004faa1675b35mr1798664pfb.69.1649133907892; Mon, 04 Apr 2022 21:45:07 -0700 (PDT) Received: from [2620:149:e0:5001:802d:575f:f87f:0] ([2620:149:e0:5001::af9]) by smtp.gmail.com with ESMTPSA id h5-20020a17090a648500b001caa7d7bf59sm713956pjj.9.2022.04.04.21.45.07 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Apr 2022 21:45:07 -0700 (PDT) Date: Mon, 4 Apr 2022 21:45:06 -0700 From: Dave Ekhaus To: "pgsql-generallists.postgresql.org" Message-ID: <1362aceb-cc4a-45f4-b57d-0b56b878ca83@Canary> Subject: JSON question MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="624bc952_6a2342ec_fc60" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --624bc952_6a2342ec_fc60 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi All I'm experimenting with PostgreSQL's JSON features and have a question. Say we have the following JSON (which will be stored in a table named 'resources' - in its 'schema' column ... { "name": { "type": "string", "label": "Name", "accessor": "name", "is_association": false }, "books": { "type": "array", "label": "Books", "accessor": "books", "is_association": true }, "email": { "type": "string", "label": "Email", "accessor": "email", "is_association": false }, "date_of_birth": { "type": "date", "label": "Birthday", "accessor": "date_of_birth", "is_association": false } } [NOTE: the JSON above is the 'schema' attribute of one record in the 'resources' table. There will be many rows in the 'resources' table] How can I query the 'resources' table to return the rows in which there's at least one JSON object whose 'type' equals 'array' ? Thanks Dave --624bc952_6a2342ec_fc60 Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline <= img id=3D=2231390D7979103852420E4=464=462D2BC59B=22 alt=3D=22=22 width=3D= =220px=22 src=3D=22https://read-receipts.canarymail.io:8100/track/1A65456= 5A262D9D25E43EDED64762BBA=5F31390D7979103852420E4=464=462D2BC59B.png=22 h= eight=3D=220px=22>
Hi All

=C2=A0 =C2=A0 I'm experimenting with PostgreSQL's JSON f= eatures and have a question. =C2=A0=C2=A0

=C2=A0= =C2=A0 Say we have the following JSON (which will be stored in a table n= amed 'resources' - in its 'schema' column ...

=7B=
=C2=A0 =22name=22: =7B
=C2=A0 =C2=A0 =22type=22: =22= string=22,
=C2=A0 =C2=A0 =22label=22: =22Name=22,
=C2= =A0 =C2=A0 =22accessor=22: =22name=22,
=C2=A0 =C2=A0 =22is=5Fas= sociation=22: false
=C2=A0 =7D,
=C2=A0 =22books=22: =7B=
=C2=A0 =C2=A0 =22type=22: =22array=22,
=C2=A0 =C2=A0= =22label=22: =22Books=22,
=C2=A0 =C2=A0 =22accessor=22: =22boo= ks=22,
=C2=A0 =C2=A0 =22is=5Fassociation=22: true
=C2= =A0 =7D,
=C2=A0 =22email=22: =7B
=C2=A0 =C2=A0 =22typ= e=22: =22string=22,
=C2=A0 =C2=A0 =22label=22: =22Email=22,
=C2=A0 =C2=A0 =22accessor=22: =22email=22,
=C2=A0 =C2=A0= =22is=5Fassociation=22: false
=C2=A0 =7D,
=C2=A0 =22= date=5Fof=5Fbirth=22: =7B
=C2=A0 =C2=A0 =22type=22: =22date=22,=
=C2=A0 =C2=A0 =22label=22: =22Birthday=22,
=C2=A0 =C2= =A0 =22accessor=22: =22date=5Fof=5Fbirth=22,
=C2=A0 =C2=A0 =22i= s=5Fassociation=22: false
=C2=A0 =7D
=7D
=C2=A0 =C2=A0 =5BNOTE: the JSON above is the 'schema' attrib= ute of one record in the 'resources' table. =C2=A0 There will be many row= s in the 'resources' table=5D

=C2=A0 =C2=A0 How = can I query the 'resources' table to return the rows in which there's at = least one JSON object whose 'type' equals 'array' =3F


Thanks
Dave
--624bc952_6a2342ec_fc60--