【问题标题】:LAG SQL operation not working in Amazon RedshiftLAG SQL 操作在 Amazon Redshift 中不起作用
【发布时间】:2019-02-24 14:20:05
【问题描述】:

我不断收到错误:

语法错误:在“,”或附近行:4 位置:3

尝试为来自 Amazon Redshift 的会话创建跟踪时在 Periscope 上。当我尝试仅查询 id、时间戳和 LAG 操作时,LAG 操作似乎会引发错误。

    SELECT 
      id 
      , timestamp
      , SUM(is_new_session) OVER (ORDER BY id, timestamp) AS global_session_id
      , SUM(is_new_session) OVER (PARTITION BY id ORDER BY timestamp) AS user_session_id
     FROM (SELECT -- creates session
            id
            , timestamp 
            , CASE 
               WHEN EXTRACT('EPOCH' FROM timestamp) - EXTRACT('EPOCH' 
                 FROM last_event) >= (60 * 10) OR last_event IS NULL THEN 1 
               ELSE 0 
               END AS is_new_session
           FROM (SELECT                      
                  id 
                  , timestamp
                  , LAG(timestamp,1) OVER (PARTITION BY id ORDER BY timestamp) AS last_event
                 FROM ios.tracks) last
           ) final

【问题讨论】:

  • 添加rows unbounded preceding子句。
  • ios.tracks 上的 id 列是什么?它是独一无二的吗?
  • id 列是段传递给 redshift 以执行不同操作的匿名 id。
  • 已修复。谢谢@VamsiPrabhala

标签: sql amazon-redshift periscope


【解决方案1】:

timestamp 是保留字。可能需要始终将其指定为 "timestamp" 或为该列使用不同的名称。

https://docs.aws.amazon.com/redshift/latest/dg/r_pg_keywords.html

【讨论】:

    猜你喜欢
    • 2017-06-04
    • 2015-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-12
    • 2015-10-28
    • 1970-01-01
    • 2013-07-03
    相关资源
    最近更新 更多