0
votes

I keep getting the error:

Syntax Error: at or near "," Line: 4 Position: 3

on Periscope when trying to create tracking for sessions from Amazon Redshift. The LAG operation seems to throw the error when I try to just query id, timestamp and the LAG operation.

    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
1
add rows unbounded preceding clause. - Vamsi Prabhala
what is id column on ios.tracks? is it unique? - Jon Scott
id column is the anonymous id that segment passes to redshift for different actions. - Cris Pineda
Fixed it. Thanks @VamsiPrabhala - Cris Pineda

1 Answers

1
votes

timestamp is a reserved word. Probably need to specify it always as "timestamp" or use a different name for the column.

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