无法在 Bigquery 中将时间列从字符串更改为时间

发布于 2025-01-19 07:57:49 字数 609 浏览 0 评论 0原文

我有一个用hh:mm:ss在excel中制作的列,但是当我将其移至bigquery时,它保留了格式,但已更改为字符串。我需要更改它,以便可以找到平均值。

起初,我只是尝试更改表:

ALTER TABLE `circular-nova-330422.trip_data_Cyclist.trip_data-12mths`
ALTER COLUMN ride_length SET DATA TYPE TIME;

但是有一个错误:

Alter Table Alter列集数据类型要求现有列类型(String)可分配给新类型(TIME)

我在这里发现一个问题,说我应该使用Parse_time,但是当我这样做时,我只是明白了:

SELECT PARSE_TIME("%H:%M:%S", ride_length)
FROM `circular-nova-330422.trip_data_Cyclist.trip_data-12mths`;

无法解析输入字符串“

我在做什么错,还有另一种永久更改数据类型的方法吗?

I have a column that I made as HH:MM:SS in Excel, but when I moved it to Bigquery, it kept the format but changed to string. I need to change it back so that I can find averages.

At first I just tried altering the table:

ALTER TABLE `circular-nova-330422.trip_data_Cyclist.trip_data-12mths`
ALTER COLUMN ride_length SET DATA TYPE TIME;

But got this error:

ALTER TABLE ALTER COLUMN SET DATA TYPE requires that the existing column type (STRING) is assignable to the new type (TIME)

I found a question on here saying I should use parse_time, but when I do that, I just get this:

SELECT PARSE_TIME("%H:%M:%S", ride_length)
FROM `circular-nova-330422.trip_data_Cyclist.trip_data-12mths`;

Failed to parse input string"

What am I doing wrong, is there another way to permanently change the data type?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南风几经秋 2025-01-26 07:57:49

这将解析 00:00:00 到 23:59:59 之间的任何时间戳,

这是您的ride_length值的格式吗?

是否还有任何行的值可能为空字符串?

SELECT PARSE_TIME("%H:%M:%S", "") 将导致您在上面发布的错误。

要解决这个问题,你可以尝试

SELECT PARSE_TIME("%H:%M:%S", nullif(ride_length, ""))
FROM `circular-nova-330422.trip_data_Cyclist.trip_data-12mths`;

This will parse any time stamp between 00:00:00 to 23:59:59

is this the format your ride_length values come in as?

also are there any rows that may have empty string as the value?

SELECT PARSE_TIME("%H:%M:%S", "") would result in the error you posted above.

to resolve this you could try

SELECT PARSE_TIME("%H:%M:%S", nullif(ride_length, ""))
FROM `circular-nova-330422.trip_data_Cyclist.trip_data-12mths`;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文