Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert Timestamp to Date Data Type in Google Bigquery

I am trying to convert Timestamp data type columns to Date datatype using:

bq query -q --destination_table=NEW_DATE_TABLE --replace "SELECT DATE(CURR_DT) AS CURR_DT from TEST.DATE_TABLE"

The new table shows the column as STRING rather than date. Is there a way to convert timestamp to date data type.

Requested Screenshot

like image 311
DWPro Avatar asked Sep 07 '16 15:09

DWPro


1 Answers

If you use Standard SQL, you can do the following:

SELECT * REPLACE(EXTRACT(DATE FROM curr_dt)) AS curr_dt FROM test.date_table

If curr_dt is repeated field, then the solution will look the following:

SELECT * REPLACE(
  ARRAY(
    SELECT EXTRACT(DATE FROM curr_dt) FROM t.curr_dt
  ) AS curr_dt)
FROM test.date_table t
like image 66
Mosha Pasumansky Avatar answered Oct 04 '22 13:10

Mosha Pasumansky