Hello,
I encountered a case that needs compose the main query from multiple subqueries which also have dependency queries. However, The final query didn't work as expected. I will show the case in an example.
--------------------- subQuery1 ---------------------
%%bq query -n subQuery1
select state, name, year
from `bigquery-public-data.usa_names.usa_1910_2013`
limit 10
subQuery1 works.
--------------------- subQuery2 ---------------------
%%bq query -n subQuery2 --subqueries subQuery1
,
subQuery2_q1 as (
select state, name
from subQuery1
limit 10
)
select *
from subQuery2_q1
subQuery2 works with subQuery1 as dependency.
Since subQuery2 has its own common table expression, then comma is needed at the front to make it working.
--------------------- main Query ---------------------
%%bq query -n mainQuery --subqueries subQuery2
select *
from subQuery2
limit 10
main query will look like,
WITH subQuery1 AS (
select state, name, year
from `bigquery-public-data.usa_names.usa_1910_2013`
limit 10
),
subQuery2 AS (
,
subQuery2_q1 as (
select state, name
from subQuery1
limit 10
)
select *
from subQuery2_q1
)
select *
from subQuery2
limit 10
In this case, the main query won't work, because subQuery2 here is not valid.
I am looking at the _recurse_subqueries functionhere, instead of putting subQuery1 and subQuery2 into a flat list, should subQuery1 be inside of subQuery2?
And Query should be,
with subQuery2 AS (
WITH subQuery1 AS (
select state, name, year
from `bigquery-public-data.usa_names.usa_1910_2013`
limit 10
),
subQuery2_q1 as (
select state, name
from subQuery1
limit 10
)
select *
from subQuery2_q1
)
select *
from subQuery2
limit 10
or
WITH subQuery1 AS (
select state, name, year
from `bigquery-public-data.usa_names.usa_1910_2013`
limit 10
),
subQuery2 AS (
with subQuery2_q1 as (
select state, name
from subQuery1
limit 10
)
select *
from subQuery2_q1
)
select *
from subQuery2
limit 10
thanks a lot.
Hello,
I encountered a case that needs compose the main query from multiple subqueries which also have dependency queries. However, The final query didn't work as expected. I will show the case in an example.
--------------------- subQuery1 ---------------------
subQuery1 works.
--------------------- subQuery2 ---------------------
subQuery2 works with subQuery1 as dependency.
Since subQuery2 has its own common table expression, then comma is needed at the front to make it working.
--------------------- main Query ---------------------
main query will look like,
In this case, the main query won't work, because subQuery2 here is not valid.
I am looking at the _recurse_subqueries functionhere, instead of putting subQuery1 and subQuery2 into a flat list, should subQuery1 be inside of subQuery2?
And Query should be,
or
thanks a lot.