...

Text file src/cloud.google.com/go/bigquery/README.md

Documentation: cloud.google.com/go/bigquery

     1## BigQuery [![Go Reference](https://pkg.go.dev/badge/cloud.google.com/go/bigquery.svg)](https://pkg.go.dev/cloud.google.com/go/bigquery)
     2
     3- [About BigQuery](https://cloud.google.com/bigquery/)
     4- [API documentation](https://cloud.google.com/bigquery/docs)
     5- [Go client documentation](https://pkg.go.dev/cloud.google.com/go/bigquery)
     6- [Complete sample programs](https://github.com/GoogleCloudPlatform/golang-samples/tree/main/bigquery)
     7
     8### Example Usage
     9
    10First create a `bigquery.Client` to use throughout your application:
    11[snip]:# (bq-1)
    12```go
    13c, err := bigquery.NewClient(ctx, "my-project-ID")
    14if err != nil {
    15	// TODO: Handle error.
    16}
    17```
    18
    19Then use that client to interact with the API:
    20[snip]:# (bq-2)
    21```go
    22// Construct a query.
    23q := c.Query(`
    24    SELECT year, SUM(number)
    25    FROM [bigquery-public-data:usa_names.usa_1910_2013]
    26    WHERE name = "William"
    27    GROUP BY year
    28    ORDER BY year
    29`)
    30// Execute the query.
    31it, err := q.Read(ctx)
    32if err != nil {
    33	// TODO: Handle error.
    34}
    35// Iterate through the results.
    36for {
    37	var values []bigquery.Value
    38	err := it.Next(&values)
    39	if err == iterator.Done {  // from "google.golang.org/api/iterator"
    40		break
    41	}
    42	if err != nil {
    43		// TODO: Handle error.
    44	}
    45	fmt.Println(values)
    46}
    47```

View as plain text