如何修复:Python代码中的BigQuery查询

时间:2019-07-31 20:47:12

标签: python google-bigquery python-bigquery

我尝试在BigQuery查询中使用变量。语法错误。可能是什么问题?

我尝试了带有'''但结果相同的字符串块。


QUERY = ('WITH activity_data AS ('
          'SELECT user_pseudo_id, event_timestamp, event_name,' 
          'UNIX_MICROS(TIMESTAMP("'+ cohort_date_str'\", "Europe/Budapest")) AS start_day,'
          '3600*1000*1000*24*1 AS one_interval_micros'
          'FROM `events_*`'
          "WHERE _table_suffix BETWEEN \'"+ table_start_str "\' AND \'"+ table_end_str1 "\'"  
          'AND event_name IN ("z_Added","y_Added","x_Added")'
          'AND user_pseudo_id IN ('
                                    'SELECT user_pseudo_id'
                                    'FROM `events_*`' 
                                    "WHERE _table_suffix BETWEEN \'"+ table_start_str"\' AND \'"+ table_end_str2"\'"
                                    'AND event_name = "first_open"'
                                    'AND event_timestamp BETWEEN UNIX_MICROS(TIMESTAMP("'+ cohort_date_str'", "Europe/Budapest"))'
                                    'AND UNIX_MICROS(TIMESTAMP("'+ cohort_date_end_str'", "Europe/Budapest"))'

 """      
                                 )
                                )
...
 """

第18行的语法错误:Colab中的小箭头将破折号指向该行的结尾。

LINE 18:
 'UNIX_MICROS(TIMESTAMP("'+ cohort_date_str'\", "Europe/Budapest")) AS start_day,'

有关错误的屏幕截图: https://image.prntscr.com/image/rpuNg96iRom9-n7qaTvILA.png

1 个答案:

答案 0 :(得分:0)

您在+之后丢失+ cohort_date_str。与+ table_start_str相同。等