在预定查询bigquery中声明变量;
我正在开发一个预定的查询,其中我正在使用with语句加入并从BigQuery滤掉几张表。为了过滤日期,我想声明以下变量: 声明初始日期;
SET initial = DATE_TRUNC(DATE_TRUNC(CURRENT_DATE(), MONTH)+7,ISOWEEK);
SET final = LAST_DAY(DATE_TRUNC(CURRENT_DATE(), MONTH)+7, ISOWEEK);
但是,在执行此查询时,我会得到两个结果。一个用于声明的变量(我对将它们作为输出不感兴趣),而最终选择的语句(作为我感兴趣的结果)。
主要问题是,每当我尝试将该计划的查询连接到Google Data Studio中的表时,我会收到以下错误:
无效的值:configuration.query.destinationtable无法为脚本设置;
如何声明变量而不结果是结束的变量?
在这里,您有一个我正在尝试使用的代码示例:
DECLARE initial, final DATE;
SET initial = DATE_TRUNC(DATE_TRUNC(CURRENT_DATE(), MONTH)+7,ISOWEEK);
SET final = LAST_DAY(DATE_TRUNC(CURRENT_DATE(), MONTH)+7, ISOWEEK);
WITH HelloWorld AS (
SELECT shop_date, revenue
FROM fulltable
WHERE shop_date >= initial
AND shop_date <= final
)
SELECT * from HelloWorld;
I am developing a scheduled query where I am using the WITH statement to join and filtrate several tables from BigQuery. To filtrate the dates, I would like to declare the following variables:
DECLARE initial, final DATE;
SET initial = DATE_TRUNC(DATE_TRUNC(CURRENT_DATE(), MONTH)+7,ISOWEEK);
SET final = LAST_DAY(DATE_TRUNC(CURRENT_DATE(), MONTH)+7, ISOWEEK);
However, when executing this query, I am getting two results; one for the variables declared (which I am not interested in having them as output), and the WITH statement that is selected at the end (which as the results that I am interested in).
The principal problem is that, whenever I try t connect this scheduled query to a table in Google Data Studio I get the following error:
Invalid value: configuration.query.destinationTable cannot be set for scripts;
How can I declare a variable without getting it as a result at the end?
Here you have a sample of the code I am trying work in:
DECLARE initial, final DATE;
SET initial = DATE_TRUNC(DATE_TRUNC(CURRENT_DATE(), MONTH)+7,ISOWEEK);
SET final = LAST_DAY(DATE_TRUNC(CURRENT_DATE(), MONTH)+7, ISOWEEK);
WITH HelloWorld AS (
SELECT shop_date, revenue
FROM fulltable
WHERE shop_date >= initial
AND shop_date <= final
)
SELECT * from HelloWorld;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 config 表只有1行并将其与您的表进行跨加入,您的查询可以像下面一样写入。
With config table having just 1 row and cross-joining it with your table, your query can be written like below.
我使用过的几个模式:
则使用config(键)来检索值。
或者,
,然后使用TimeZone()获取值。
它每次都会执行该功能,因此不要在其中做一些昂贵的事情(例如从另一个表中选择)。
A few patterns I've used:
Then use config(key) to retrieve the value.
Or,
Then use timezone() to get the value.
It would execute the function each time, so don't do something expensive in there (like SELECT from another table).