Delete materialized view Stay organized with collections Save and categorize content based on your preferences.
Delete a materialized view.
Explore further
For detailed documentation that includes this code sample, see the following:
Code sample
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""cloud.google.com/go/bigquery")// deleteMaterializedView demonstrates deletion of a BigQuery materialized view.funcdeleteMaterializedView(projectID,datasetID,viewIDstring)error{// projectID := "my-project-id"// datasetID := "mydataset"// tableID := "myview"ctx:=context.Background()client,err:=bigquery.NewClient(ctx,projectID)iferr!=nil{returnfmt.Errorf("bigquery.NewClient: %w",err)}deferclient.Close()view:=client.Dataset(datasetID).Table(viewID)iferr:=view.Delete(ctx);err!=nil{returnerr}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.TableId;// Sample to delete materialized viewpublicclassDeleteMaterializedView{publicstaticvoidmain(String[]args){// TODO(developer): Replace these variables before running the sample.StringdatasetName="MY_DATASET_NAME";StringmaterializedViewName="MY_MATERIALIZED_VIEW_NAME";deleteMaterializedView(datasetName,materializedViewName);}publicstaticvoiddeleteMaterializedView(StringdatasetName,StringmaterializedViewName){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,materializedViewName);booleansuccess=bigquery.delete(tableId);if(success){System.out.println("Materialized view deleted successfully");}else{System.out.println("Materialized view was not found");}}catch(BigQueryExceptione){System.out.println("Materialized view was not found. \n"+e.toString());}}}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.cloudimportbigquerybigquery_client=bigquery.Client()view_id="my-project.my_dataset.my_materialized_view"# Make an API request to delete the materialized view.bigquery_client.delete_table(view_id)What's next
To search and filter code samples for other Google Cloud products, see theGoogle Cloud sample browser.
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.