如何将日期字段从String更改为Date或DateTime? [英] How can I change a date field from String to Date or DateTime?

查看:39
本文介绍了如何将日期字段从String更改为Date或DateTime?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Google Big Query,并且有一个名为"AsOfDate"的字段,该字段设置为字符串数据类型.我在此字段中有一堆数据,我真的想将其设置为DateTime或仅仅是Date.都可以.我用Google搜索了一个解决方案,我认为这很容易做到,但是我似乎无法更新数据类型.我不想运行一个简单的select语句;我想永久更改架构.有没有人碰到这个,并想出如何做这种事情?如果是这样,请分享您的见解.谢谢!

I an using Google Big Query and I have a field, named 'AsOfDate' which is set as a string datatype. I have a bunch of data in this field, which I really want to set as DateTime or just Date. Either is fine. I Googled for a solution, and I thought this would be pretty easy to do, but I can't seem to get the data type updated. I don't want to run a simple select statement; I want to permanently change the Schema. Has anyone run into this and figured out how to do this kind of thing? If so, please share your insights. Thanks!

推荐答案

直接引用官方文档:' BigQuery Web UI,命令行工具或API ."

To quote directly from the official documentation: 'Changing a column's data type is not supported by the BigQuery web UI, the command-line tool, or the API.'

https://cloud.google.com/bigquery/docs/manually-changing-schemas#changing_a_columns_data_type

有两种方法可以手动更改列的数据类型:

There are two ways to manually change a column's data type:

使用SQL查询-如果您更担心此问题,请选择此选项简单易用,并且您不必担心成本.

Using a SQL query — Choose this option if you are more concerned about simplicity and ease of use, and you are less concerned about costs.

重新创建表格-如果您更担心,请选择此选项关于成本,而您则不太关心简单性和易用性使用.

Recreating the table — Choose this option if you are more concerned about costs, and you are less concerned about simplicity and ease of use.

您可以使用上述两种方法中的任一种以及 PARSE_DATE()函数将字符串转换为日期字段.

You could use either of the approaches above along with the PARSE_DATE() function to transform your string into a date field.

https://cloud.google.com/bigquery/docs/reference/standard-sql/functions-and-operators#parse_date

这篇关于如何将日期字段从String更改为Date或DateTime?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆