I'm wondering if it's possible to do a left outer join between a json_array_elements of a table column and another table? Something like the following, but this doesn't work.
SELECT *
FROM foo,
json_array_elements (foo.bars :: json) foo_bars
LEFT OUTER JOIN bar ON (foo_bars ->> 'id') :: BIGINT = bar.ID;
The table structure is like the following
FOO
------------------------------------------
| ID | NAME | BARS |
|------------------------------------------|
| 1 | FOO1 | [{ "id" : 1}, { "id" : 2 }]|
|------------------------------------------|
| 2 | FOO1 | [] |
------------------------------------------
BAR
-------------
| ID | NAME |
|-------------|
| 1 | BAR1 |
|-------------|
| 2 | BAR2 |
-------------
I would expect the output of the query to be
--------------------------------------------------------
| ID | NAME | BARS | ID | NAME |
|------------------------------------------|-------------|
| 1 | FOO1 | [{ "id" : 1}, { "id" : 2 }]| 1 | BAR1 |
|------------------------------------------|-------------|
| 1 | FOO1 | [{ "id" : 1}, { "id" : 2 }]| 2 | BAR2 |
|------------------------------------------|-------------|
| 2 | FOO1 | [] | null | null |
--------------------------------------------------------