Your question is SQL: Timed Out Activity IDs. Start with the requirements and the two tables on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Google Cloud Workflows records each execution of an activity, including retries. Write a PostgreSQL query that returns the IDs of activities whose latest execution has timed out as of 2025-02-01 12:00:00.
An execution is timed out when it is the latest execution for its activity, its status is running or timed_out, its completed_at is NULL, and the activity deadline is at or before the evaluation timestamp.
ROW_NUMBER() to identify the latest execution for each activity by started_at.activities and apply the timeout conditions.activity_id, ordered ascending.NULL deadline.| Column | Type | Description |
|---|---|---|
| activity_idPK | INTEGER | Unique activity identifier |
| activity_name | VARCHAR(100) | Human-readable activity name |
| timeout_at | TIMESTAMP | Deadline for the activity execution |
| Column | Type | Description |
|---|---|---|
| execution_idPK | INTEGER | Unique execution identifier |
| activity_id | INTEGER | Referenced activity |
| status | VARCHAR(20) | Execution state |
| started_at | TIMESTAMP | Execution start timestamp |
| completed_at | TIMESTAMP | Completion timestamp, if completed |