无法在 Bigquery 中将时间列从字符串更改为时间
我有一个用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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这将解析 00:00:00 到 23:59:59 之间的任何时间戳,
这是您的ride_length值的格式吗?
是否还有任何行的值可能为空字符串?
SELECT PARSE_TIME("%H:%M:%S", "") 将导致您在上面发布的错误。
要解决这个问题,你可以尝试
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