With this data:
create or replace table test_json as
select
parse_json('{
"include": [
"x",
"y",
"z"
]
}') AS val
union all
select
parse_json('{
"exclude": [
"a",
"b"
],
"include": [
"d",
"e"
]
}');
I have this query:
with source_cte as (
select val, i.value::TEXT as include_symbol
from test_json, lateral flatten(input=>val:include) as i
)
select
include_symbol,
e.value::TEXT as exclude_symbol
from source_cte LEFT JOIN LATERAL FLATTEN(input=>val:exclude) e
Here is the result:
INCLUDE_SYMBOL EXCLUDE_SYMBOL
d a
d b
e a
e b
It doesn't return rows with include = x, y, z, like it would if I used INNER JOIN LATERAL FLATTEN, but I'm using LEFT JOIN.
Is it some bug in Snowflake?
How to achieve then LEFT JOIN behaviour for such case? I mean to show include_symbol regardless of whether match is found in left join lateral flatten
expression (and show nulls in exlude_symbol column in such case).
outer => true
option that is noted in the documentation. docs.snowflake.com/en/sql-reference/functions/flatten