Add a label to a query job

Populate the labels property of the job configuration to add labels while inserting the job.

Code sample

Rust

use google_cloud_bigquery::client::BigQuery;

pub async fn sample(project_id: &str) -> anyhow::Result<()> {
    let client = BigQuery::builder().build().await?;

    let mut rows = client
        .query(
            r#"
SELECT name
FROM `bigquery-public-data.usa_names.usa_1910_2013`
WHERE state = 'TX'
LIMIT 10
"#,
        )
        .with_project_id(project_id)
        .set_labels(vec![
            ("environment", "production"),
            ("team", "data-analytics"),
        ])
        .set_location("US")
        .run()
        .await?
        .until_done()
        .await?
        .read();

    while let Some(row) = rows.next().await.transpose()? {
        let name: String = row.get("name");
        println!("Name: {name}");
    }
    Ok(())
}

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.