Reputation: 1
I've got a table with 3 fields: userID, url and a loged datetime of user action. I want to write a query in sql Redshift in Redash, which returns a list of user session (all actions which have less that an hour between them) with fields userID, start datetime and end datetime. What can I use to achieve this?
Upvotes: 0
Views: 1847
Reputation: 1081
My $0.02, I use the following query since it excludes "lost connections" and only shows ones with active sessions. It also shows the running query if there is one.
-- Who
SELECT s.user_name,
s.process,
s.starttime,
s.db_name,
c.remotehost,
si.starttime query_start_time,
si.text query
FROM stv_sessions s
LEFT JOIN stl_connection_log c
ON s.user_name = c.username AND s.process = c.pid AND c.event = 'authenticated'
LEFT JOIN stv_inflight si ON c.pid = si.pid
WHERE s.user_name <> 'rdsdb'
ORDER BY user_name, starttime;
Upvotes: 0
Reputation: 14035
Have a look at the view v_connection_summary.sql
in our GitHub repo.
Upvotes: 3