Trying to convert epoch code field (string type) to timestamp











up vote
2
down vote

favorite












Trying to convert from epoch code to timestamp, in legacy SQL it's working fine and in standard SQL I'm getting an error.
Field name custom_field_6 (string type field) represent epoch time and I want to convert it to timestamp (in standard SQL)



In legacy SQL I did the following:
select
custom_field_6 as custom_field_6,
timestamp(custom_field_6) as custom_field_6_convert
FROM [yellowhead-visionbi-rivery:yellowhead_prod.affise_conversions]



The query output



In standard sql:



select
custom_field_6 as custom_field_6,
cast(custom_field_6 as date) as custom_field_6_converted
FROM
yellowhead-visionbi-rivery.yellowhead_prod.affise_conversions``



The error I get: "invalid date"










share|improve this question




























    up vote
    2
    down vote

    favorite












    Trying to convert from epoch code to timestamp, in legacy SQL it's working fine and in standard SQL I'm getting an error.
    Field name custom_field_6 (string type field) represent epoch time and I want to convert it to timestamp (in standard SQL)



    In legacy SQL I did the following:
    select
    custom_field_6 as custom_field_6,
    timestamp(custom_field_6) as custom_field_6_convert
    FROM [yellowhead-visionbi-rivery:yellowhead_prod.affise_conversions]



    The query output



    In standard sql:



    select
    custom_field_6 as custom_field_6,
    cast(custom_field_6 as date) as custom_field_6_converted
    FROM
    yellowhead-visionbi-rivery.yellowhead_prod.affise_conversions``



    The error I get: "invalid date"










    share|improve this question


























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      Trying to convert from epoch code to timestamp, in legacy SQL it's working fine and in standard SQL I'm getting an error.
      Field name custom_field_6 (string type field) represent epoch time and I want to convert it to timestamp (in standard SQL)



      In legacy SQL I did the following:
      select
      custom_field_6 as custom_field_6,
      timestamp(custom_field_6) as custom_field_6_convert
      FROM [yellowhead-visionbi-rivery:yellowhead_prod.affise_conversions]



      The query output



      In standard sql:



      select
      custom_field_6 as custom_field_6,
      cast(custom_field_6 as date) as custom_field_6_converted
      FROM
      yellowhead-visionbi-rivery.yellowhead_prod.affise_conversions``



      The error I get: "invalid date"










      share|improve this question















      Trying to convert from epoch code to timestamp, in legacy SQL it's working fine and in standard SQL I'm getting an error.
      Field name custom_field_6 (string type field) represent epoch time and I want to convert it to timestamp (in standard SQL)



      In legacy SQL I did the following:
      select
      custom_field_6 as custom_field_6,
      timestamp(custom_field_6) as custom_field_6_convert
      FROM [yellowhead-visionbi-rivery:yellowhead_prod.affise_conversions]



      The query output



      In standard sql:



      select
      custom_field_6 as custom_field_6,
      cast(custom_field_6 as date) as custom_field_6_converted
      FROM
      yellowhead-visionbi-rivery.yellowhead_prod.affise_conversions``



      The error I get: "invalid date"







      google-bigquery






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 21 at 20:03









      Felipe Hoffa

      20.5k249104




      20.5k249104










      asked Nov 21 at 15:39









      ornachshon

      133




      133
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          Below id for BigQuery Standard SQL



          #standardSQL
          SELECT
          custom_field_6,
          TIMESTAMP_SECONDS(CAST(custom_field_6 AS INT64)) custom_field_6_convert
          FROM `yellowhead-visionbi-rivery.yellowhead_prod.affise_conversions`


          you can test it using dummy data as below



          #standardSQL
          WITH `project.dataset.table` AS (
          SELECT '1540051185' custom_field_6 UNION ALL
          SELECT '1540252572'
          )
          SELECT
          custom_field_6,
          TIMESTAMP_SECONDS(CAST(custom_field_6 AS INT64)) custom_field_6_convert
          FROM `project.dataset.table`


          with result



          Row custom_field_6  custom_field_6_convert   
          1 1540051185 2018-10-20 15:59:45 UTC
          2 1540252572 2018-10-22 23:56:12 UTC





          share|improve this answer





















          • This is the error I get: Query Failed Error: Bad int64 value: {installed_at} Job ID: yellowhead-visionbi-rivery:US.bquijob_70505117_1673a6cfa50
            – ornachshon
            Nov 22 at 7:58












          • Provide example of your data
            – Mikhail Berlyant
            Nov 22 at 8:05










          • Hi. It's working. Thank you.
            – ornachshon
            Nov 22 at 8:40













          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53415587%2ftrying-to-convert-epoch-code-field-string-type-to-timestamp%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote



          accepted










          Below id for BigQuery Standard SQL



          #standardSQL
          SELECT
          custom_field_6,
          TIMESTAMP_SECONDS(CAST(custom_field_6 AS INT64)) custom_field_6_convert
          FROM `yellowhead-visionbi-rivery.yellowhead_prod.affise_conversions`


          you can test it using dummy data as below



          #standardSQL
          WITH `project.dataset.table` AS (
          SELECT '1540051185' custom_field_6 UNION ALL
          SELECT '1540252572'
          )
          SELECT
          custom_field_6,
          TIMESTAMP_SECONDS(CAST(custom_field_6 AS INT64)) custom_field_6_convert
          FROM `project.dataset.table`


          with result



          Row custom_field_6  custom_field_6_convert   
          1 1540051185 2018-10-20 15:59:45 UTC
          2 1540252572 2018-10-22 23:56:12 UTC





          share|improve this answer





















          • This is the error I get: Query Failed Error: Bad int64 value: {installed_at} Job ID: yellowhead-visionbi-rivery:US.bquijob_70505117_1673a6cfa50
            – ornachshon
            Nov 22 at 7:58












          • Provide example of your data
            – Mikhail Berlyant
            Nov 22 at 8:05










          • Hi. It's working. Thank you.
            – ornachshon
            Nov 22 at 8:40

















          up vote
          1
          down vote



          accepted










          Below id for BigQuery Standard SQL



          #standardSQL
          SELECT
          custom_field_6,
          TIMESTAMP_SECONDS(CAST(custom_field_6 AS INT64)) custom_field_6_convert
          FROM `yellowhead-visionbi-rivery.yellowhead_prod.affise_conversions`


          you can test it using dummy data as below



          #standardSQL
          WITH `project.dataset.table` AS (
          SELECT '1540051185' custom_field_6 UNION ALL
          SELECT '1540252572'
          )
          SELECT
          custom_field_6,
          TIMESTAMP_SECONDS(CAST(custom_field_6 AS INT64)) custom_field_6_convert
          FROM `project.dataset.table`


          with result



          Row custom_field_6  custom_field_6_convert   
          1 1540051185 2018-10-20 15:59:45 UTC
          2 1540252572 2018-10-22 23:56:12 UTC





          share|improve this answer





















          • This is the error I get: Query Failed Error: Bad int64 value: {installed_at} Job ID: yellowhead-visionbi-rivery:US.bquijob_70505117_1673a6cfa50
            – ornachshon
            Nov 22 at 7:58












          • Provide example of your data
            – Mikhail Berlyant
            Nov 22 at 8:05










          • Hi. It's working. Thank you.
            – ornachshon
            Nov 22 at 8:40















          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted






          Below id for BigQuery Standard SQL



          #standardSQL
          SELECT
          custom_field_6,
          TIMESTAMP_SECONDS(CAST(custom_field_6 AS INT64)) custom_field_6_convert
          FROM `yellowhead-visionbi-rivery.yellowhead_prod.affise_conversions`


          you can test it using dummy data as below



          #standardSQL
          WITH `project.dataset.table` AS (
          SELECT '1540051185' custom_field_6 UNION ALL
          SELECT '1540252572'
          )
          SELECT
          custom_field_6,
          TIMESTAMP_SECONDS(CAST(custom_field_6 AS INT64)) custom_field_6_convert
          FROM `project.dataset.table`


          with result



          Row custom_field_6  custom_field_6_convert   
          1 1540051185 2018-10-20 15:59:45 UTC
          2 1540252572 2018-10-22 23:56:12 UTC





          share|improve this answer












          Below id for BigQuery Standard SQL



          #standardSQL
          SELECT
          custom_field_6,
          TIMESTAMP_SECONDS(CAST(custom_field_6 AS INT64)) custom_field_6_convert
          FROM `yellowhead-visionbi-rivery.yellowhead_prod.affise_conversions`


          you can test it using dummy data as below



          #standardSQL
          WITH `project.dataset.table` AS (
          SELECT '1540051185' custom_field_6 UNION ALL
          SELECT '1540252572'
          )
          SELECT
          custom_field_6,
          TIMESTAMP_SECONDS(CAST(custom_field_6 AS INT64)) custom_field_6_convert
          FROM `project.dataset.table`


          with result



          Row custom_field_6  custom_field_6_convert   
          1 1540051185 2018-10-20 15:59:45 UTC
          2 1540252572 2018-10-22 23:56:12 UTC






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 21 at 16:03









          Mikhail Berlyant

          54.5k43368




          54.5k43368












          • This is the error I get: Query Failed Error: Bad int64 value: {installed_at} Job ID: yellowhead-visionbi-rivery:US.bquijob_70505117_1673a6cfa50
            – ornachshon
            Nov 22 at 7:58












          • Provide example of your data
            – Mikhail Berlyant
            Nov 22 at 8:05










          • Hi. It's working. Thank you.
            – ornachshon
            Nov 22 at 8:40




















          • This is the error I get: Query Failed Error: Bad int64 value: {installed_at} Job ID: yellowhead-visionbi-rivery:US.bquijob_70505117_1673a6cfa50
            – ornachshon
            Nov 22 at 7:58












          • Provide example of your data
            – Mikhail Berlyant
            Nov 22 at 8:05










          • Hi. It's working. Thank you.
            – ornachshon
            Nov 22 at 8:40


















          This is the error I get: Query Failed Error: Bad int64 value: {installed_at} Job ID: yellowhead-visionbi-rivery:US.bquijob_70505117_1673a6cfa50
          – ornachshon
          Nov 22 at 7:58






          This is the error I get: Query Failed Error: Bad int64 value: {installed_at} Job ID: yellowhead-visionbi-rivery:US.bquijob_70505117_1673a6cfa50
          – ornachshon
          Nov 22 at 7:58














          Provide example of your data
          – Mikhail Berlyant
          Nov 22 at 8:05




          Provide example of your data
          – Mikhail Berlyant
          Nov 22 at 8:05












          Hi. It's working. Thank you.
          – ornachshon
          Nov 22 at 8:40






          Hi. It's working. Thank you.
          – ornachshon
          Nov 22 at 8:40




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53415587%2ftrying-to-convert-epoch-code-field-string-type-to-timestamp%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Berounka

          Sphinx de Gizeh

          Different font size/position of beamer's navigation symbols template's content depending on regular/plain...