If you have a variable declaration in your query, the entire query returns no data, whether or not that variable is even used. These variables all work fine when run on BQ's console or via Python.
Simple reprex:
library(bigrquery)
library(DBI)
chr.query <- "
DECLARE test_date DATE DEFAULT DATE('2025-05-26');
SELECT test_date
"
tmp <- dbGetQuery(bq.con, chr.query)
print(tmp)
chr.query <- "
DECLARE test_date DATE DEFAULT DATE('2025-05-26');
SELECT DATE('2025-05-26')
"
tmp <- dbGetQuery(bq.con, chr.query)
print(tmp)
chr.query <- "
SELECT DATE('2025-05-26')
"
tmp <- dbGetQuery(bq.con, chr.query)
print(tmp)
which returns, in console:
> library(bigrquery)
> library(DBI)
>
> chr.query <- "
+ DECLARE test_date DATE DEFAULT DATE('2025-05-26');
+ SELECT test_date
+ "
> tmp <- dbGetQuery(bq.con, chr.query)
Job complete
Billed: 0 B
> print(tmp)
# A tibble: 0 × 1
# ℹ 1 variable: test_date <chr>
>
> chr.query <- "
+ DECLARE test_date DATE DEFAULT DATE('2025-05-26');
+ SELECT DATE('2025-05-26')
+ "
> tmp <- dbGetQuery(bq.con, chr.query)
Job complete
Billed: 0 B
> print(tmp)
# A tibble: 0 × 1
# ℹ 1 variable: f0_ <chr>
>
> chr.query <- "
+ SELECT DATE('2025-05-26')
+ "
> tmp <- dbGetQuery(bq.con, chr.query)
Job complete
Billed: 0 B
Downloading first chunk of data.
First chunk includes all requested rows.
> print(tmp)
# A tibble: 1 × 1
f0_
<date>
1 2025-05-26
Much obliged!
If you have a variable declaration in your query, the entire query returns no data, whether or not that variable is even used. These variables all work fine when run on BQ's console or via Python.
Simple reprex:
which returns, in console:
Much obliged!