I'm creating a view of a table that I have in 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.
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
:
https://cloud.google.com/bigquery/docs/information-schema-tables#table_options_view
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.