简体   繁体   English

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

[英]Unable to change my time column from string to time in Bigquery

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.我有一个专栏,我在 Excel 中制作为 HH:MM:SS,但是当我将它移至 Bigquery 时,它保留了格式但更改为字符串。 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) ALTER TABLE ALTER COLUMN SET DATA TYPE 要求现有列类型 (STRING) 可分配给新类型 (TIME)

I found a question on here saying I should use parse_time, but when I do that, I just get this:我在这里发现了一个问题,说我应该使用 parse_time,但是当我这样做时,我得到了这个:

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?我做错了什么,还有另一种方法可以永久更改数据类型吗?

This will parse any time stamp between 00:00:00 to 23:59:59这将解析 00:00:00 到 23:59:59 之间的任何时间戳

is this the format your ride_length values come in as?这是您的 ride_length 值的格式吗?

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. SELECT PARSE_TIME("%H:%M:%S", "") 会导致您在上面发布的错误。

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`;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM