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 1jg5uC-00074o-6Z for pgsql-general@arkaria.postgresql.org; Tue, 02 Jun 2020 12:20:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jg5uA-0007ll-Pu for pgsql-general@arkaria.postgresql.org; Tue, 02 Jun 2020 12:20:30 +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 1jg5uA-0007lc-Fs for pgsql-general@lists.postgresql.org; Tue, 02 Jun 2020 12:20:30 +0000 Received: from mail-ej1-x644.google.com ([2a00:1450:4864:20::644]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jg5u4-0007jM-Ab for pgsql-general@postgresql.org; Tue, 02 Jun 2020 12:20:29 +0000 Received: by mail-ej1-x644.google.com with SMTP id y13so12547871eju.2 for ; Tue, 02 Jun 2020 05:20:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=a6QrictHaR5WFNPeLoO3rFSd0ZaZXYTMA/WttjxRJZE=; b=H+OlC41V2bap6Nm7d1XhamvFComYZ7hTJCKPQzFexiLKQku5xi39aYEaXKnhtRcOgM 2ixoANC3ceUoIS9ZHKmCY7zY2ZYkU91lmsNffd8QZZmmXNgZAsFBq07DWlPMtb1A4Ahv mcPoqCHALaDskoq6Fhf7uqscI2jkXxKWAVFHS0f2mHr+B423Iy/yP+8KoivsU5ziTnL6 X/bRPzc2FPLmbhc9JBGYe+7Y3l3ahyHxy9An1P9GMH1m5XqimJ7yyEWRzdt2jhOtEuY0 2YXTMoMvxdc0mcJn9u7lf7nwlt1iPK/yljZB2g4bjuwmeb57MYvC0EqZeF+N60YFTjj4 mkEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=a6QrictHaR5WFNPeLoO3rFSd0ZaZXYTMA/WttjxRJZE=; b=CFyygAbx1oFwFm4tkfJt6ieQJiBCpzQMF6a6hxTwFIpPSd0ev1Bq0fVvlVxy9yOGsC 2bw6uNEfEvqgwXrrea8yxGugq2eY7BKChHK76P4b7V6H1/oeTEHYFJ4/LHKh4Rf5+aYn T8hHVEusAKs9Cd8Xne4yNdVJJ5ky3a/uTsjGF/mC3lUZJReBQoDipZxgjxQX9BQ9BHLZ osVcIPUWg6AacrWrAhmUfjMDw42wmrb0HWL5dF1v7HOK8WXpQ4WsruaxKFwn8pmP6L51 fWuIz64EkwUp98ypg6rwRhls16YR6M4+GSpBzUYuh+KtO3/IvT6ZNFI6LXMDrkFhSYN7 vcrg== X-Gm-Message-State: AOAM533YdnwkGp6E4WbZsyCe1FH4zGsG21zxsIqcKTxNb9A3sMCDuvz1 HD0UZaDCtio50vfeO5stJNQ= X-Google-Smtp-Source: ABdhPJxNbBSlVGwCCpOHZkQn1ud5C7JFzVeXFIWpmRNleBt1v4a2OOBgFdO+DttgZIA766yTYYK72Q== X-Received: by 2002:a17:906:3441:: with SMTP id d1mr22682422ejb.489.1591100422836; Tue, 02 Jun 2020 05:20:22 -0700 (PDT) Received: from hollewijn.internal (217-19-30-105.dsl.cambrium.nl. [217.19.30.105]) by smtp.gmail.com with ESMTPSA id g25sm1495357edq.34.2020.06.02.05.20.20 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Jun 2020 05:20:21 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Subject: Re: Using JSONB with nested key-value structures, and skipping/wildcarding the key From: Alban Hertroys In-Reply-To: Date: Tue, 2 Jun 2020 14:20:20 +0200 Cc: pgsql-general@postgresql.org Content-Transfer-Encoding: quoted-printable Message-Id: References: <960EE185-1107-4BB8-9D10-4F7ECAC923B2@gmail.com> To: Shaheed Haque X-Mailer: Apple Mail (2.3445.104.11) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk > On 2 Jun 2020, at 9:30, Shaheed Haque wrote: >=20 >=20 >> I do something like this to get a set of sub-paths in a JSONB field = (no idea how to write that in Django): >>=20 >> select snapshot->=E2=80=99pay_definition=E2=80=99->k.value->=E2=80=99na= me=E2=80=99 >> from MyModel >> join lateral jsonb_object_keys(snapshot->=E2=80=99pay_definition=E2=80= =99) k(value) on true >>=20 > I was unaware of the LATERAL keyword, so thanks. After a bit of = Googling however, it seems that it is tricky/impossible to use from the = ORM (barring a full scale escape to a "raw" query). One question: as a = novice here, I think I understand the right hand side of your JOIN "... = k(value)" is shorthand for: >=20 > ... AS table_name(column_name) >=20 > except that I don't see any clues in the docs that jsonb_object_keys() = is a "table function". Can you kindly clarify? Correct. Thomas already explained the return type, but the plural form = of the function name is also an indication that it returns multiple = results. Alban Hertroys -- If you can't see the forest for the trees, cut the trees and you'll find there is no forest.