use*_*794 2 go google-bigquery
这里基本上是我在 golang 中为 bigquery 创建的脚本:
type data_pix struct {
Id string
IdC string
Stamp int64
Tag []string
}
func createTable(client *bigquery.Client, datasetID, tableID string) error {
ctx := context.Background()
// [START bigquery_create_table]
schema, err := bigquery.InferSchema(data_pix{})
if err != nil {
return err
}
table := client.Dataset(datasetID).Table(tableID)
if err := table.Create(ctx, schema); err != nil {
return err
}
// [END bigquery_create_table]
return nil
}
Run Code Online (Sandbox Code Playgroud)
目前我主要使用 Int64 中的时间戳。
但我正在寻找任何关于如何将 Datetime 添加到我的结构和顺便说一下将 Datetime 添加到我的数据的示例
感谢致敬
我没有使用过 bigquery,但是我查看了godoc和源代码。
看来,您必须在结构中使用数据类型civil.DateTime 引用。
例如:
根据 godoc 和源代码,以下应创建DateTime字段。
type data_pix struct {
Id string
IdC string
Stamp civil.DateTime
Tag []string
}
schema, err := bigquery.InferSchema(data_pix{})
// now schema should represent DateTime Field
Run Code Online (Sandbox Code Playgroud)
有一个函数可以civil.DateTime从time.Time. 我建议您查看此go 源代码以了解更多信息。