Setting Big Query variables like mysql

前端 未结 5 576
鱼传尺愫
鱼传尺愫 2020-12-28 15:04

what is the bigquery equivalent to mysql variables like?

SET @fromdate = \'2014-01-01 00:00:00\',  -- dates for after 2013
@todate=\'2015-01-01 00:00:00\',

         


        
5条回答
  •  鱼传尺愫
    2020-12-28 15:35

    You can now use variables in BigQuery. To run the statements that you provided, you need to use DECLARE:

    DECLARE fromdate TIMESTAMP DEFAULT '2014-01-01 00:00:00';  -- dates for after 2013
    DECLARE todate TIMESTAMP DEFAULT '2015-01-01 00:00:00';
    
    DECLARE bfromdate TIMESTAMP DEFAULT '2005-01-01 00:00:00'; -- dates for before 2013
    DECLARE btodate TIMESTAMP DEFAULT '2005-01-01 00:00:00';
    
    DECLARE achfromdate TIMESTAMP DEFAULT '2013-01-01 00:00:00'; -- dates for ACH without submit time in 2013
    DECLARE achtodate TIMESTAMP DEFAULT '2013-01-01 00:00:00';
    
    DECLARE currency STRING DEFAULT "USD";
    

    You can use variables in statements after declaring them, e.g.:

    DECLARE fromdate TIMESTAMP DEFAULT '2014-01-01 00:00:00';  -- dates for after 2013
    DECLARE todate TIMESTAMP DEFAULT '2015-01-01 00:00:00';
    
    SELECT FORMAT('From %t to %t', fromdate, todate);
    

    See also the scripting documentation.

提交回复
热议问题