且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Google BigQuery中将时间戳转换为日期数据类型

更新时间:2023-01-30 19:14:48

如果您使用 Standard SQL ,您可以执行以下操作:

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



如果curr_dt是重复字段,那么解决方案将显示如下:

$ p $ SELECT $ REPLACE
ARRAY (
SELECT EXTRACT(date from curr_dt)FROM t.curr_dt
)AS curr_dt)
FROM test.date_table t


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 datatype.

Requested Screenshot

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