Delete a scheduled query
Stay organized with collections
Save and categorize content based on your preferences.
Delete the configuration for a scheduled query, stopping any future runs.
Code sample
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License
, and code samples are licensed under the Apache 2.0 License
. For details, see the Google Developers Site Policies
. Java is a registered trademark of Oracle and/or its affiliates.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],[],[[["\u003cp\u003eThis page provides code samples in Go and Java for deleting a scheduled query in BigQuery, effectively stopping any future runs of that query.\u003c/p\u003e\n"],["\u003cp\u003eThe Go code sample demonstrates how to use the \u003ccode\u003edatatransfer\u003c/code\u003e client library to delete a scheduled query by its configuration ID.\u003c/p\u003e\n"],["\u003cp\u003eThe Java code sample shows how to use the \u003ccode\u003eDataTransferServiceClient\u003c/code\u003e to delete a scheduled query, also requiring its configuration ID.\u003c/p\u003e\n"],["\u003cp\u003eBoth code examples require setting up Application Default Credentials for authentication and referencing the BigQuery client library quickstart guide for initial setup.\u003c/p\u003e\n"]]],[],null,["# Delete a scheduled query\n\nDelete the configuration for a scheduled query, stopping any future runs.\n\nCode sample\n-----------\n\n### Go\n\n\nBefore trying this sample, follow the Go setup instructions in the\n[BigQuery quickstart using\nclient libraries](/bigquery/docs/quickstarts/quickstart-client-libraries).\n\n\nFor more information, see the\n[BigQuery Go API\nreference documentation](https://godoc.org/cloud.google.com/go/bigquery).\n\n\nTo authenticate to BigQuery, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for client libraries](/bigquery/docs/authentication#client-libs).\n\n import (\n \t\"context\"\n \t\"fmt\"\n\n \tdatatransfer \"cloud.google.com/go/bigquery/datatransfer/apiv1\"\n \t\"cloud.google.com/go/bigquery/datatransfer/apiv1/datatransferpb\"\n )\n\n // deleteScheduledQuery delete a scheduled query based on\n // the config ID, stopping any future runs.\n // transferConfigID follows the format:\n //\n //\t`projects/{project_id}/locations/{location_id}/transferConfigs/{config_id}`\n //\tor `projects/{project_id}/transferConfigs/{config_id}`\n func deleteScheduledQuery(transferConfigID string) error {\n \t// transferConfigID := \"projects/{project_id}/transferConfigs/{config_id}\"\n \tctx := context.Background()\n \tdtc, err := datatransfer.https://cloud.google.com/go/docs/reference/cloud.google.com/go/bigquery/latest/datatransfer/apiv1.html#cloud_google_com_go_bigquery_datatransfer_apiv1_Client_NewClient(ctx)\n \tif err != nil {\n \t\treturn fmt.Errorf(\"datatransfer.NewClient: %w\", err)\n \t}\n \tdefer dtc.https://cloud.google.com/go/docs/reference/cloud.google.com/go/bigquery/latest/datatransfer/apiv1.html#cloud_google_com_go_bigquery_datatransfer_apiv1_Client_Close()\n\n \treq := &datatransferpb.DeleteTransferConfigRequest{\n \t\tName: transferConfigID,\n \t}\n \terr = dtc.DeleteTransferConfig(ctx, req)\n \tif err != nil {\n \t\treturn fmt.Errorf(\"dtc.DeleteTransferConfig: %w\", err)\n \t}\n\n \treturn nil\n }\n\n### Java\n\n\nBefore trying this sample, follow the Java setup instructions in the\n[BigQuery quickstart using\nclient libraries](/bigquery/docs/quickstarts/quickstart-client-libraries).\n\n\nFor more information, see the\n[BigQuery Java API\nreference documentation](/java/docs/reference/google-cloud-bigquery/latest/overview).\n\n\nTo authenticate to BigQuery, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for client libraries](/bigquery/docs/authentication#client-libs).\n\n import com.google.api.gax.rpc.https://cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.rpc.ApiException.html;\n import com.google.cloud.bigquery.datatransfer.v1.https://cloud.google.com/java/docs/reference/google-cloud-bigquerydatatransfer/latest/com.google.cloud.bigquery.datatransfer.v1.DataTransferServiceClient.html;\n import com.google.cloud.bigquery.datatransfer.v1.https://cloud.google.com/java/docs/reference/google-cloud-bigquerydatatransfer/latest/com.google.cloud.bigquery.datatransfer.v1.DeleteTransferConfigRequest.html;\n import java.io.IOException;\n\n // Sample to delete a scheduled query\n public class DeleteScheduledQuery {\n\n public static void main(String[] args) throws IOException {\n // TODO(developer): Replace these variables before running the sample.\n // i.e projects/{project_id}/transferConfigs/{config_id}` or\n // `projects/{project_id}/locations/{location_id}/transferConfigs/{config_id}`\n String name = \"MY_CONFIG_ID\";\n deleteScheduledQuery(name);\n }\n\n public static void deleteScheduledQuery(String name) throws IOException {\n try (https://cloud.google.com/java/docs/reference/google-cloud-bigquerydatatransfer/latest/com.google.cloud.bigquery.datatransfer.v1.DataTransferServiceClient.html dataTransferServiceClient = https://cloud.google.com/java/docs/reference/google-cloud-bigquerydatatransfer/latest/com.google.cloud.bigquery.datatransfer.v1.DataTransferServiceClient.html.create()) {\n https://cloud.google.com/java/docs/reference/google-cloud-bigquerydatatransfer/latest/com.google.cloud.bigquery.datatransfer.v1.DeleteTransferConfigRequest.html request =\n https://cloud.google.com/java/docs/reference/google-cloud-bigquerydatatransfer/latest/com.google.cloud.bigquery.datatransfer.v1.DeleteTransferConfigRequest.html.newBuilder().setName(name).build();\n dataTransferServiceClient.deleteTransferConfig(request);\n System.out.print(\"Scheduled query deleted successfully.\\n\");\n } catch (https://cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.rpc.ApiException.html ex) {\n System.out.print(\"Scheduled query was not deleted.\" + ex.toString());\n }\n }\n }\n\nWhat's next\n-----------\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=bigquerydatatransfer)."]]