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












2















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





























    2















    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



























      2












      2








      2








      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 '18 at 20:03









      Felipe Hoffa

      22.5k252120




      22.5k252120










      asked Nov 21 '18 at 15:39









      ornachshonornachshon

      213




      213
























          1 Answer
          1






          active

          oldest

          votes


















          1














          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 '18 at 7:58













          • Provide example of your data

            – Mikhail Berlyant
            Nov 22 '18 at 8:05











          • Hi. It's working. Thank you.

            – ornachshon
            Nov 22 '18 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',
          autoActivateHeartbeat: false,
          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









          1














          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 '18 at 7:58













          • Provide example of your data

            – Mikhail Berlyant
            Nov 22 '18 at 8:05











          • Hi. It's working. Thank you.

            – ornachshon
            Nov 22 '18 at 8:40


















          1














          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 '18 at 7:58













          • Provide example of your data

            – Mikhail Berlyant
            Nov 22 '18 at 8:05











          • Hi. It's working. Thank you.

            – ornachshon
            Nov 22 '18 at 8:40
















          1












          1








          1







          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 '18 at 16:03









          Mikhail BerlyantMikhail Berlyant

          61.8k43773




          61.8k43773













          • 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 '18 at 7:58













          • Provide example of your data

            – Mikhail Berlyant
            Nov 22 '18 at 8:05











          • Hi. It's working. Thank you.

            – ornachshon
            Nov 22 '18 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 '18 at 7:58













          • Provide example of your data

            – Mikhail Berlyant
            Nov 22 '18 at 8:05











          • Hi. It's working. Thank you.

            – ornachshon
            Nov 22 '18 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 '18 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 '18 at 7:58















          Provide example of your data

          – Mikhail Berlyant
          Nov 22 '18 at 8:05





          Provide example of your data

          – Mikhail Berlyant
          Nov 22 '18 at 8:05













          Hi. It's working. Thank you.

          – ornachshon
          Nov 22 '18 at 8:40







          Hi. It's working. Thank you.

          – ornachshon
          Nov 22 '18 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.




          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

          Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

          ComboBox Display Member on multiple fields

          Is it possible to collect Nectar points via Trainline?