Skip to content

Combine multiple lazy queries into a single query using UNION ALL. This is a convenient wrapper around purrr::reduce(tables, union_all). Like dplyr::bind_rows() (and unlike UNION ALL), bind_queries() will automatically align columns based on their name, and fill in any missing columns with missing values.

Usage

bind_queries(...)

Arguments

...

<dynamic-dots> Lazy tables to combine.

Value

A lazy query.

Examples

lf1 <- lazy_frame(x = 1, y = "a")
lf2 <- lazy_frame(x = 2, y = "b")
bind_queries(lf1, lf2)
#> <SQL>
#> SELECT *
#> FROM "df"
#> 
#> UNION ALL
#> 
#> SELECT *
#> FROM "df"

lf3 <- lazy_frame(y = "c", x = 3, z = 10)
bind_queries(lf2, lf3)
#> <SQL>
#> SELECT "df".*, NULL AS "z"
#> FROM "df"
#> 
#> UNION ALL
#> 
#> SELECT "x", "y", "z"
#> FROM "df"

# If you already have a list, you can use splice operator
queries <- list(lf1, lf2)
bind_queries(!!!queries)
#> <SQL>
#> SELECT *
#> FROM "df"
#> 
#> UNION ALL
#> 
#> SELECT *
#> FROM "df"