pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Ken Tanzer <ken.tanzer@gmail.com>
Cc: Steve Baldwin <steve.baldwin@gmail.com>
Cc: David G. Johnston <david.g.johnston@gmail.com>
Cc: Rob Sargent <robjsargent@gmail.com>
Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: Extracting data from jsonb array?
Date: Tue, 08 Dec 2020 00:54:06 -0500
Message-ID: <3214468.1607406846@sss.pgh.pa.us> (raw)
In-Reply-To: <CAD3a31WpcdcGHiXGgNAVVxDikwPP+cMthuE8EP3NrM37-iHUyA@mail.gmail.com>
References: <CAD3a31UQuYmXLuHLFtF1NTZyFSjdHfAKeSkie8GT5K_2ahAh=Q@mail.gmail.com>
	<CAKE1AiaA7f_KJL0Qre=2Cnev4geGsrGmdbFPQYLpfCZnMS=DkQ@mail.gmail.com>
	<CAKFQuwaxB6bK_CSJaWM=OXjXya7BaV+3Pwpp9e4dPPSfB0CSrQ@mail.gmail.com>
	<CAD3a31VDRAV8_snO9SbxwJa77=aUJJTcsSvCRnc1v5mG8NqDkA@mail.gmail.com>
	<CAKFQuwY710pBKLXDhaGD-Sg27FOZro5uZ7GvBO8=aHbUYYWyWg@mail.gmail.com>
	<CAD3a31WNrMJq5bxQZ2+z5pEQU=wAn7Gtx2ahSmt6w5LiLqs57A@mail.gmail.com>
	<72f54672-ad66-0370-9128-206e49389b60@gmail.com>
	<CAKFQuwaXHneeDSiR8hdZNnr4AFtU5BwVsCWY9YuCEP0DqJB+ag@mail.gmail.com>
	<f2651149-c274-3cea-651d-891f71843960@gmail.com>
	<CAD3a31XxwRS8cXT+wBQCdr=Urug0rRe_RCTQ9ATS=RXNLr4zDA@mail.gmail.com>
	<CAKFQuwYQcgnEczC8j37U3UuXDmCR7+7_s=M=gs97YM=mesrd_A@mail.gmail.com>
	<CAKE1Aibh8ekYEVpCZyCQyt0L9-75G7D=PV_b8Wht02DsQHZR5Q@mail.gmail.com>
	<CAD3a31V_1fGMGUx=v7CqrHE0kho+GpfhYtxfyEOV+Q4J-MuP2g@mail.gmail.com>
	<CAD3a31Vr_xZXnayJTu_iRvEUHRy4_P3jDqptDimFgp_xWQQMyA@mail.gmail.com>
	<3210187.1607400978@sss.pgh.pa.us>
	<CAD3a31WBtf0Wzy! puW6-Q-WOtTqa-dkit1TEC-PkJzHOr1nd_xA@mail.gmail.com>
	<3211450.1607402699@sss.pgh.pa.us>
	<CAD3a31WpcdcGHiXGgNAVVxDikwPP+cMthuE8EP3NrM37-iHUyA@mail.gmail.com>

Ken Tanzer <ken.tanzer@gmail.com> writes:
> There's one last piece of this query I'm clearly not getting though.  Where
> it says:

> from foo as f, jsonb_to_recordset(js) as t(key2 text)

> what is actually going on there?  I keep reading this as a table foo (f)
> cross-joined to a table created by jsonb_to_recordset (t).  But that
> doesn't seem right, because rows from t are only joining with matching rows
> from f, rather than all of them.  Is there some unspoken implicit logic
> going on here, or something else entirely that is going over my head?

There's an implicit LATERAL there:

  ... from foo as f, lateral jsonb_to_recordset(js) as t(key2 text)

ie, for each row of foo, extract the foo.js column and evaluate
jsonb_to_recordset(js) --- which, in this case, produces multiple
rows that are joined to the original foo row.  This is again a
SQL-ism.  I don't particularly care for their choice to allow
LATERAL to be implicit for function-call-like FROM items,
because it seems pretty confusing; but the spec is the spec.

[ thinks for a bit... ]  Again, I'm too lazy to go digging in
the spec's dense verbiage at this hour, but I'm vaguely recalling
that they may only require this behavior for the one case of
the function being UNNEST().  I think it was our choice to allow
it to work like that for any set-returning function.

			regards, tom lane





view thread (25+ messages)  latest in thread

Message-ID: <3214468.1607406846@sss.pgh.pa.us>
Permalink:  ../3214468.1607406846@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/3214468.1607406846@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: tgl@sss.pgh.pa.us, ken.tanzer@gmail.com, steve.baldwin@gmail.com, david.g.johnston@gmail.com, robjsargent@gmail.com
  Subject: Re: Extracting data from jsonb array?
  In-Reply-To: <3214468.1607406846@sss.pgh.pa.us>
  References: <CAD3a31UQuYmXLuHLFtF1NTZyFSjdHfAKeSkie8GT5K_2ahAh=Q@mail.gmail.com> <CAD3a31VDRAV8_snO9SbxwJa77=aUJJTcsSvCRnc1v5mG8NqDkA@mail.gmail.com> <CAKFQuwY710pBKLXDhaGD-Sg27FOZro5uZ7GvBO8=aHbUYYWyWg@mail.gmail.com> <CAD3a31WNrMJq5bxQZ2+z5pEQU=wAn7Gtx2ahSmt6w5LiLqs57A@mail.gmail.com> <72f54672-ad66-0370-9128-206e49389b60@gmail.com> <CAKFQuwaXHneeDSiR8hdZNnr4AFtU5BwVsCWY9YuCEP0DqJB+ag@mail.gmail.com> <f2651149-c274-3cea-651d-891f71843960@gmail.com> <CAD3a31XxwRS8cXT+wBQCdr=Urug0rRe_RCTQ9ATS=RXNLr4zDA@mail.gmail.com> <CAKFQuwYQcgnEczC8j37U3UuXDmCR7+7_s=M=gs97YM=mesrd_A@mail.gmail.com> <CAKE1Aibh8ekYEVpCZyCQyt0L9-75G7D=PV_b8Wht02DsQHZR5Q@mail.gmail.com> <CAD3a31V_1fGMGUx=v7CqrHE0kho+GpfhYtxfyEOV+Q4J-MuP2g@mail.gmail.com> <CAD3a31Vr_xZXnayJTu_iRvEUHRy4_P3jDqptDimFgp_xWQQMyA@mail.gmail.com> <3210187.1607400978@sss.pgh.pa.us> <3211450.1607402699@sss.pgh.pa.us> <CAD3a31WpcdcGHiXGgNAVVxDikwPP+cMthuE8EP3NrM37-iHUyA@mail.gmail.com> <3214468.1607406846@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox