How to create a DateTime field in bigquery and update it in golang?

huangapple go评论83阅读模式
英文:

How to create a DateTime field in bigquery and update it in golang?

问题

以下是基本的用于在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
}

目前,我主要使用Int64类型的时间戳。但我正在寻找如何在我的结构体中添加日期时间以及如何将日期时间添加到我的数据的示例。

谢谢!祝好!

英文:

here is basically my creation script for bigquery in golang :

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
}

for the moment i use mainly a timestamp in Int64.

But i am looking for any example on how to add Datetime to my struct and btw add Datetime to my data

Thanks and regards

答案1

得分: 9

我还没有使用过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{})
// 现在schema应该表示DateTime字段

有一个函数可以从time.Time获取civil.DateTime。我建议你查看这个go源代码以了解更多信息。

英文:

I have not used the bigquery, however I had a look at the godoc and source code.

It seems, you have to use data type civil.DateTime reference in the struct.

For e.g:

As per godoc and source code, following should create DateTime field.

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

There is a function to get civil.DateTime from time.Time. I would suggest you have a look at this go sourcecode to know more.

huangapple
  • 本文由 发表于 2017年6月20日 07:00:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/44641199.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定