I have a source table which has dates stored in string format as below:
1984-10-28 00:00:00
1988-11-22 00:00:00
1990-01-08 00:00:00
1983-06-22 00:00:00
Then created a table test1 as below:
mk -t xyz.test birthdate:timestamp
When I write a query to convert all the dates from source table to timestamp and save it to test1 it gives an error:
SELECT FORMAT_UTC_USEC(birthdate) AS birthdate FROM [sourcetable] LIMIT 10
Error: Invalid schema update. Field birthdate has changed type
Job ID: [Project]:job_5P4gFVl4wiYuyXL0vY5VZNtCZOU
Please help if I am doing anything wrong
The format is: YYYY-MM-DD HH:MM:SS (e.g. 2021-05-15 16:45:23). Timestamp type: Date, time, and time zone information are all included in timestamps. If no time zone is given, the format falls back to UTC. The format is: YYYY-MM-DD [Timezone] HH:MM:SS (e.g. 2021-05-15 16:45:18 UTC).
BigQuery stores TIMESTAMP data internally as a UNIX timestamp with microsecond precision. A positive or negative decimal number. A positive number specifies the number of seconds since the epoch (1970-01-01 00:00:00 UTC), and a negative number specifies the number of seconds before the epoch.
Never mind. I found it. I was overlooking a big part of bigquery's query reference document.
TIMESTAMP()
Convert a date string to a TIMESTAMP data type.
SELECT TIMESTAMP("2012-10-01 01:02:03");
Returns: 2012-10-01 01:02:03 UTC
So the correct query as below: SELECT TIMESTAMP(birthdate) AS birthdate FROM [sourcetable] LIMIT 10
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With