I have this view in Snowflake:
create or replace view foo as
select $1 as id_foo, $2 as sales
from (values (1,100),(2,200),(3,300));
And this user-defined table function:
CREATE OR REPLACE FUNCTION build_aux_table ( restriction number )
RETURNS TABLE ( aux_id number )
AS 'select $1 as aux_id from (VALUES (1),(2),(3)) where aux_id = restriction';
The following query works, and returns 3 rows:
select id_foo, baz.aux_id
from foo
cross join table(build_aux_table(foo.id_foo)) baz;
However, I didn't expect the query to compile, because the UDTF-generated table with which we are joining depends on a column from the first table. My understanding was that this sort of intra-table dependency required a LATERAL join, like the following (which also works):
select id_foo, baz.aux_id
from foo
cross join lateral build_aux_table(foo.id_foo) baz;
Why does the query without LATERAL work?