Getting information about views

This document describes how to list, get information about, and see metadata forviews in BigQuery.

You can list views in datasets by:

  • Using the Google Cloud console
  • Using thebq ls command in the bq command-line tool
  • Calling thetables.listAPI method
  • Using the client libraries

Before you begin

Grant Identity and Access Management (IAM) roles that give users the necessary permissionsto perform each task in this document.

List views

Listing views is identical to the process for listing tables.

Required permissions

To list views in a dataset, you need thebigquery.tables.listIAM permission.

Each of the following predefined IAM roles includes thepermissions that you need in order to list views in a dataset:

  • roles/bigquery.user
  • roles/bigquery.metadataViewer
  • roles/bigquery.dataViewer
  • roles/bigquery.dataOwner
  • roles/bigquery.dataEditor
  • roles/bigquery.admin

For more information on IAM roles and permissions inBigQuery, seePredefined roles and permissions.

List views in a dataset

To list the views in a dataset:

Console

  1. In the left pane, clickExplorer:

    Highlighted button for the Explorer pane.

    If you don't see the left pane, clickExpand left pane to open the pane.

  2. In theExplorer pane, expand your project, clickDatasets, andthen select a dataset.

  3. ClickOverview> Tables. Scroll through the list to seethe view in the dataset. Tables and views are identified by the valuesin theType column.

SQL

Use theINFORMATION_SCHEMA.VIEWS view:

  1. In the Google Cloud console, go to theBigQuery page.

    Go to BigQuery

  2. In the query editor, enter the following statement:

    SELECTtable_nameFROMDATASET_ID.INFORMATION_SCHEMA.VIEWS;

    ReplaceDATASET_ID with the name of the dataset.

  3. ClickRun.

For more information about how to run queries, seeRun an interactive query.

bq

Issue thebq ls command. The--format flag can be used to control theoutput. If you are listing views in a project other than your defaultproject, add the project ID to the dataset in the following format:project_id:dataset.

bqls--format=prettyproject_id:dataset

Where:

  • project_id is your project ID.
  • dataset is the name of the dataset.

When you run the command, theType field displays eitherTABLE orVIEW. For example:

+-------------------------+-------+----------------------+-------------------+|         tableId         | Type  |        Labels        | Time Partitioning |+-------------------------+-------+----------------------+-------------------+| mytable                 | TABLE | department:shipping  |                   || myview                  | VIEW  |                      |                   |+-------------------------+-------+----------------------+-------------------+

Examples:

Enter the following command to list views in datasetmydataset in yourdefault project.

bq ls --format=pretty mydataset

Enter the following command to list views in datasetmydataset inmyotherproject.

bq ls --format=pretty myotherproject:mydataset

API

To list views using the API, call thetables.listmethod.

Go

Before trying this sample, follow theGo setup instructions in theBigQuery quickstart using client libraries. For more information, see theBigQueryGo API reference documentation.

To authenticate to BigQuery, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.

import("context""fmt""io""cloud.google.com/go/bigquery""google.golang.org/api/iterator")// listTables demonstrates iterating through the collection of tables in a given dataset.funclistTables(wio.Writer,projectID,datasetIDstring)error{// projectID := "my-project-id"// datasetID := "mydataset"// tableID := "mytable"ctx:=context.Background()client,err:=bigquery.NewClient(ctx,projectID)iferr!=nil{returnfmt.Errorf("bigquery.NewClient: %v",err)}deferclient.Close()ts:=client.Dataset(datasetID).Tables(ctx)for{t,err:=ts.Next()iferr==iterator.Done{break}iferr!=nil{returnerr}fmt.Fprintf(w,"Table: %q\n",t.TableID)}returnnil}

Python

Before trying this sample, follow thePython setup instructions in theBigQuery quickstart using client libraries. For more information, see theBigQueryPython API reference documentation.

To authenticate to BigQuery, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.

fromgoogle.cloudimportbigquery# Construct a BigQuery client object.client=bigquery.Client()# TODO(developer): Set dataset_id to the ID of the dataset that contains#                  the tables you are listing.# dataset_id = 'your-project.your_dataset'tables=client.list_tables(dataset_id)# Make an API request.print("Tables contained in '{}':".format(dataset_id))fortableintables:print("{}.{}.{}".format(table.project,table.dataset_id,table.table_id))

You can get view metadata by:

  • Using the Google Cloud console
  • Using the bq command-line tool'sbq show command
  • Calling thetables.get API method
  • Using the client libraries
  • Querying theINFORMATION_SCHEMA views

Get information about views

Getting information about views is identical to the process for gettinginformation about tables.

Required permissions

To get information about a view, you need thebigquery.tables.get IAM permission.

Each of the following predefined IAM roles includes the permissions that you need in order to get information about a view:

  • roles/bigquery.metadataViewer
  • roles/bigquery.dataViewer
  • roles/bigquery.dataOwner
  • roles/bigquery.dataEditor
  • roles/bigquery.admin

Additionally, if you have thebigquery.datasets.create permission, you can get information about views in the datasets that you create.

For more information on IAM roles and permissions inBigQuery, seePredefined roles and permissions.

To get information about views:

Console

  1. In the left pane, clickExplorer:

    Highlighted button for the Explorer pane.

  2. In theExplorer pane, expand your project, clickDatasets, andthen select a dataset.

  3. ClickOverview> Tables. Scroll through the list to seethe view in the dataset. Tables and views are identified by the valuesin theType column.

  4. Click theDetails tab that displays the view'sdescription, view information, and the SQL query that defines the view.

SQL

Query theINFORMATION_SCHEMA.VIEWS view.The following example retrieves all columns except forcheck_option,which is reserved for future use. The metadata returned is for all views inDATASET_ID in your default project:

  1. In the Google Cloud console, go to theBigQuery page.

    Go to BigQuery

  2. In the query editor, enter the following statement:

    SELECT*EXCEPT(check_option)FROMDATASET_ID.INFORMATION_SCHEMA.VIEWS;

    ReplaceDATASET_ID with the name of the dataset.

  3. ClickRun.

For more information about how to run queries, seeRun an interactive query.

bq

Issue thebq show command. The--format flag can be used to control theoutput. If you are getting information about a view in a project other thanyour default project, add the project ID to the dataset in the followingformat:[PROJECT_ID]:[DATASET].

bqshow\--format=prettyjson\project_id:dataset.view

Where:

  • project_id is your project ID.
  • dataset is the name of the dataset.
  • view is the name of the view.

Examples:

Enter the following command to display information aboutmyview indatasetmydataset in your default project.

bq show --format=prettyjson mydataset.myview

Enter the following command to display information aboutmyview indatasetmydataset inmyotherproject.

bq show --format=prettyjson myotherproject:mydataset.myview

API

Call thetables.getmethod and provide any relevant parameters.

Go

Before trying this sample, follow theGo setup instructions in theBigQuery quickstart using client libraries. For more information, see theBigQueryGo API reference documentation.

To authenticate to BigQuery, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.

import("context""fmt""io""cloud.google.com/go/bigquery")// getView demonstrates fetching the metadata from a BigQuery logical view and printing it to an io.Writer.funcgetView(wio.Writer,projectID,datasetID,viewIDstring)error{// projectID := "my-project-id"// datasetID := "mydataset"// viewID := "myview"ctx:=context.Background()client,err:=bigquery.NewClient(ctx,projectID)iferr!=nil{returnfmt.Errorf("bigquery.NewClient: %v",err)}deferclient.Close()view:=client.Dataset(datasetID).Table(viewID)meta,err:=view.Metadata(ctx)iferr!=nil{returnerr}fmt.Fprintf(w,"View %s, query: %s\n",view.FullyQualifiedName(),meta.ViewQuery)returnnil}

Java

Before trying this sample, follow theJava setup instructions in theBigQuery quickstart using client libraries. For more information, see theBigQueryJava API reference documentation.

To authenticate to BigQuery, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.

importcom.google.cloud.bigquery.BigQuery;importcom.google.cloud.bigquery.BigQueryException;importcom.google.cloud.bigquery.BigQueryOptions;importcom.google.cloud.bigquery.Table;importcom.google.cloud.bigquery.TableId;// Sample to get a viewpublicclassGetView{publicstaticvoidmain(String[]args){// TODO(developer): Replace these variables before running the sample.StringdatasetName="MY_DATASET_NAME";StringviewName="MY_VIEW_NAME";getView(datasetName,viewName);}publicstaticvoidgetView(StringdatasetName,StringviewName){try{// Initialize client that will be used to send requests. This client only needs to be created// once, and can be reused for multiple requests.BigQuerybigquery=BigQueryOptions.getDefaultInstance().getService();TableIdtableId=TableId.of(datasetName,viewName);Tableview=bigquery.getTable(tableId);System.out.println("View retrieved successfully"+view.getDescription());}catch(BigQueryExceptione){System.out.println("View not retrieved. \n"+e.toString());}}}

Node.js

Before trying this sample, follow theNode.js setup instructions in theBigQuery quickstart using client libraries. For more information, see theBigQueryNode.js API reference documentation.

To authenticate to BigQuery, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.

// Import the Google Cloud client libraryconst{BigQuery}=require('@google-cloud/bigquery');constbigquery=newBigQuery();asyncfunctiongetView(){// Retrieves view properties./**   * TODO(developer): Uncomment the following lines before running the sample   */// const datasetId = "my_dataset";// const tableId = "my_view";// Retrieve viewconstdataset=bigquery.dataset(datasetId);const[view]=awaitdataset.table(tableId).get();constfullTableId=view.metadata.id;constviewQuery=view.metadata.view.query;// Display view propertiesconsole.log(`View at${fullTableId}`);console.log(`View query:${viewQuery}`);}getView();

Python

Before trying this sample, follow thePython setup instructions in theBigQuery quickstart using client libraries. For more information, see theBigQueryPython API reference documentation.

To authenticate to BigQuery, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.

fromgoogle.cloudimportbigqueryclient=bigquery.Client()view_id="my-project.my_dataset.my_view"# Make an API request to get the table resource.view=client.get_table(view_id)# Display view propertiesprint(f"Retrieved{view.table_type}:{str(view.reference)}")print(f"View Query:\n{view.view_query}")

View security

To control access to views in BigQuery, seeAuthorized views.

What's next

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-15 UTC.