Files
query-orchestration/database/migrations/20241219161630_create_fullactivequery_view.up.sql
T

11 lines
646 B
SQL
Raw Normal View History

CREATE VIEW fullActiveQueries AS
2025-01-20 13:31:48 +00:00
SELECT DISTINCT q.id, q.type, q.activeVersion, q.latestVersion, coalesce(c.config, null) as config, ARRAY_AGG(DISTINCT r.requiredQueryId)::uuid[] as requiredIds
FROM queries AS q
LEFT JOIN queryConfigs AS c ON q.id = c.queryId
and q.activeVersion >= c.addedVersion
and q.activeVersion < COALESCE(c.removedVersion, q.activeVersion + 1)
LEFT JOIN requiredQueries AS r ON q.id = r.queryId
and q.activeVersion >= r.addedVersion
and q.activeVersion < COALESCE(r.removedVersion, q.activeVersion + 1)
2025-01-20 13:31:48 +00:00
GROUP BY q.id, q.type, q.activeversion, q.latestversion, c.config;