Search code examples
google-cloud-platformgoogle-bigquery

BigQuery: create view with comments added to the top of the query


I want to create a view in BigQuery that also shows comments such as the author, date created etc.

But if I try this in the UI the comments are left out.
Is there a way to do this in the BigQuery UI?
Or are there other ways using bq client or python, or ...?

So for example if I run this:

CREATE OR REPLACE VIEW `my_project_id.my_dataset.my_view_name`
AS
-- this is my important comment. This will be a long and extensive comment.
SELECT 1 as column_a
;

BigQuery will not show the comments in the view when the UI is used to create that view:

bq query not showing comments at the top of the query


Solution

    • First create the view without the comment.

    • Then edit the sql of that view you just created and add the comments then.

    See screenshots below.

    Choose Edit Query:

    edit view query to add comments


    Choose Save view: after you've added the comments to the sql of the view, then choose Save View