在GCP BigQuery中自动添加当前时间戳到行插入操作中

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

Automatically Adding Current Timestamp on Row Insertion in GCP BigQuery

问题

我正在寻求有关在Google Cloud Platform (GCP) BigQuery表中插入行的建议。具体来说,我想了解BigQuery是否可以在每次插入新行时自动将当前时间戳添加到一个专用列中。

我知道我可以通过从我的Java代码生成时间戳并将其包含在发送到BigQuery的数据中来实现这一点。但我想知道是否有一种方式让BigQuery自己处理这个功能,类似于一些基于SQL的关系数据库中可用的DEFAULT CURRENT_TIMESTAMP功能。

BigQuery是否有内置功能或SQL命令可以让我实现这一点,还是这个功能始终需要在应用程序级别处理(在我这种情况下是Java)?

英文:

I am seeking advice regarding the insertion of rows in a Google Cloud Platform (GCP) BigQuery table. Specifically, I am interested in understanding if it is possible for BigQuery to automatically add the current timestamp into a dedicated column each time a new row is inserted.

I am aware that I can accomplish this by generating a timestamp from my Java code and including it in the data that I'm sending to BigQuery. However, I am curious to know if there's a way for BigQuery itself to handle this functionality, similar to the DEFAULT CURRENT_TIMESTAMP feature available in some SQL-based relational databases.

Is there a built-in feature or SQL command in BigQuery that would allow me to do this, or would this functionality always need to be handled at the application level (in my case, Java)?

答案1

得分: 1

根据 @GMB,您可以使用以下查询语句:

mycol timestamp default current_timestamp

将此答案发布为社区维基,因为这是一种可能的解决方法,有利于将来可能遇到这种用例的社区成员。

英文:

According to @GMB, you can use this line of query:

mycol timestamp default current_timestamp

Posting this answer as a Community Wiki since this is a possible workaround and for the benefit of the community that might encounter this use case in the future.

huangapple
  • 本文由 发表于 2023年5月24日 20:51:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/76323746.html
匿名

发表评论

匿名网友

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

确定