parse date form string in bigquery

后端 未结 2 1182
离开以前
离开以前 2021-01-28 16:54

I have a table in bigquery that has a column name \"timeStamp\" with data type of STRING. The value in this column looks like this \"20180902\".

This is how I am trying

相关标签:
2条回答
  • 2021-01-28 17:39

    Below example shows that if value is really "20180902" as you state it should work

    #standardSQL
    WITH `project.dataset.table` AS (
      SELECT '20180902' timeStamp   
    )
    SELECT 
      `timeStamp`, 
      PARSE_DATE('%Y%m%d', timeStamp    ) AS date    
    FROM `project.dataset.table`
    

    with result as

    Row   timeStamp   date   
    1     20180902    2018-09-02     
    

    so the issue potentially in some wrong value in some rows - and you need to identify these row(s)

    0 讨论(0)
  • 2021-01-28 17:46

    I found the issue. My table had a row at the bottom that had the value "timeStamp" . Deleted that row and everything worked .

    0 讨论(0)
提交回复
热议问题