Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1egdkd-0006Md-3x for pgsql-general@arkaria.postgresql.org; Tue, 30 Jan 2018 21:47:35 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1egdkc-0002Ba-7a for pgsql-general@arkaria.postgresql.org; Tue, 30 Jan 2018 21:47:34 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1egdkb-0002BR-Sb for pgsql-general@lists.postgresql.org; Tue, 30 Jan 2018 21:47:34 +0000 Received: from mail-pf0-x22e.google.com ([2607:f8b0:400e:c00::22e]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1egdkU-0003ne-E0 for pgsql-general@lists.postgresql.org; Tue, 30 Jan 2018 21:47:33 +0000 Received: by mail-pf0-x22e.google.com with SMTP id p1so10407589pfh.4 for ; Tue, 30 Jan 2018 13:47:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rxmg-com.20150623.gappssmtp.com; s=20150623; h=from:content-transfer-encoding:mime-version:subject:message-id:date :to; bh=25eRRWVI+2YJPiWs5AVYi2hZzdwfb1E4JuxhOxw+MDM=; b=k2PRv1nTnieTuDA83SYFNpiXVBp3UAKlPyOiQcrIto+cVEB+94mBD+rQtxxQnP1sds pv8DxpcSrudGaXWN8MmFT+y1EAyV1mSCOD+f7tsvnUns0uBKU/DwXisVsG7SouYKP/1B w1RgtvYC8lvJQV1S8pwgr8Lo/hlZ5xe8WwGQGbkHBAMcV2NIsPh2vPbSuiaDdeicvlx/ HZLOgZLNwL+ikMmauUrICy2UD2lcFQ2U23NnIWoWqqe4mrfVP9xeJ9u7B8o6KZWLO+T4 MOoCA1jG6Zi4QRqBgOH6j7Qioes+kFwvIh9OtcNekEOzHArC/R6fZPHc9964XGcZ3FLy PcRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:content-transfer-encoding:mime-version :subject:message-id:date:to; bh=25eRRWVI+2YJPiWs5AVYi2hZzdwfb1E4JuxhOxw+MDM=; b=QJ5UxEly5AdAX809QB0QGKELOmxrjL1N9mGQvwHjxs88Y/a+s+oJP8jw7ZdJrmQIQb 66Dx3BO78cz3ZSB6HQy+Vo1YOHvVqnShro6wlS1gN6KSu4PrlJYyd6xcPMoPbRMe7C14 RpiZjkNbHz6cs+GrKsAdz8aieFCmM52Eh3iDbv9AcN4i5L0NywR9Gi13B9FbJoCOBXCO /NPe5+C+FrcQwvBc5wjSN9HCUpkBVVovJe0ng1V94A33QwFeZP7guagyjlS5YP0meMsj WbBxadM7ZW2pwIBW0IyHipRyG3xlPyhZS+lt0U2CWiiJ2cY4ya+ND7VPkFH+dsEW67Sx jTFg== X-Gm-Message-State: AKwxytfKOvGnI6tbgJ0KSkkZmIM4o/4V+SIVuROCHrGRjItdCA3dSGcs 9aun43pGiaXH+zfs/Iu09EKcebc+13o= X-Google-Smtp-Source: AH8x2248uiBIp/Vcs4aDQvORIPDtG8fnOMQTeckiV/QQ20+XPz/yuRkOXYBMvpbxnaTA9Zgd94WOGA== X-Received: by 2002:a17:902:a711:: with SMTP id w17-v6mr13093006plq.299.1517348842917; Tue, 30 Jan 2018 13:47:22 -0800 (PST) Received: from [192.168.222.7] (ec2-34-216-35-238.us-west-2.compute.amazonaws.com. [34.216.35.238]) by smtp.gmail.com with ESMTPSA id e20sm22452359pgn.19.2018.01.30.13.47.22 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 30 Jan 2018 13:47:22 -0800 (PST) From: geoff hoffman Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 11.2 \(3445.5.20\)) Subject: Working with JSONB data having node lists Message-Id: <93BF39AF-F96B-4437-BECE-CD7D7815CF4E@rxmg.com> Date: Tue, 30 Jan 2018 14:47:21 -0700 To: "pgsql-general@lists.postgresql.org" X-Mailer: Apple Mail (2.3445.5.20) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk JSONB fields are very attractive for our current use, particularly as = straight key-value pairs in the JSONB data; but we are having trouble finding documentation on how to query lists = (of scalars or objects) in nodes of the JSONB data. ~~~ I have the table as follows: CREATE TABLE public.contacts ( id integer NOT NULL DEFAULT nextval('contacts_id_seq'::regclass), uuid uuid NOT NULL DEFAULT gen_random_uuid(), vertical_id integer NOT NULL, inboundlog_id integer NOT NULL, email character varying(255) COLLATE pg_catalog."default" NOT NULL, data jsonb NOT NULL, created_at timestamp(0) without time zone, updated_at timestamp(0) without time zone, CONSTRAINT contacts_pkey PRIMARY KEY (id) ) WITH ( OIDS =3D FALSE ) TABLESPACE pg_default; ~~~ I have a record as follows: INSERT INTO contacts (uuid, vertical_id, inboundlog_id, email, data) VALUES (gen_random_uuid(), 1, 1, =E2=80=98phil@site.com',=20 = '{"first=E2=80=9D:"Phil","last=E2=80=9D:"Peters=E2=80=9D,"subscriptions=E2= =80=9D:[101,202,303]}') How do I craft a query to find all subscribers to program 202? ~~~ I have another record as follows: INSERT INTO contacts (uuid, vertical_id, inboundlog_id, email, data) VALUES (gen_random_uuid(), 1, 1, =E2=80=98bob@domain.com',=20 '{"first=E2=80=9D:"Bob","last=E2=80=9D:"Baker=E2=80=9D,"downloads":[{"dat= e":"2018-01-01 00:00:00","pubid=E2=80=9D:123},{"date":"2018-02-02 = 00:00:00","pubid=E2=80=9D:456}]}') How do I craft a query to find all contacts who have downloaded pubid = 123? TIA - Geoff