[英]BigQuery SQL use description of table for a description of a view
I'm creating a view of a table that I have in BigQuery.我正在创建我在 BigQuery 中的表的视图。
How can I get the description of the table and make it the description of the view?如何获取表的描述并使其成为视图的描述?
You can do this using INFORMATION_SCHEMA.TABLE_OPTIONS
to get the table description and set it to a variable.您可以使用
INFORMATION_SCHEMA.TABLE_OPTIONS
获取表描述并将其设置为变量来执行此操作。
Working example:工作示例:
-- declare variable where we will later write the table description to
DECLARE view_description STRING;
-- create an example table that has a description
CREATE OR REPLACE TABLE `your_project.your_dataset.test_table_descriptions`
OPTIONS(description="Interesting table description")
AS SELECT 1 test_column;
-- get the table description and write it to the view_description variable
SET view_description = (
SELECT option_value
FROM `your_project.your_dataset.INFORMATION_SCHEMA.TABLE_OPTIONS`
WHERE table_name = 'test_table_descriptions' and option_name = 'description');
-- create the view you want and within options use the view_description variable
CREATE OR REPLACE VIEW `your_project.your_dataset.test_table_descriptions2`
OPTIONS(description=(view_description))
AS SELECT 1 test_column_of_view;
More info on INFORMATION_SCHEMA.TABLE_OPTIONS
:有关
INFORMATION_SCHEMA.TABLE_OPTIONS
的更多信息:
https://cloud.google.com/bigquery/docs/information-schema-tables#table_options_view https://cloud.google.com/bigquery/docs/information-schema-tables#table_options_view
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.