Skip to main content

Query Expired Time Triggers (AKA: Governance Settings)

SELECT 
  count("Join2"."Id") 
FROM 
  (
    SELECT 
      "Extent1"."NodeID", 
      "Extent1"."AccountID", 
      "Extent1"."Id" 
    FROM 
      "public"."DbTriggerToNode" AS "Extent1" 
      INNER JOIN "public"."DbTriggers" AS "Extent2" ON "Extent1"."TriggerID" = "Extent2"."Id" 
      AND "Extent1"."AccountID" = "Extent2"."AccountID" 
      INNER JOIN "public"."DbTimeTriggers" AS "Extent3" ON "Extent1"."AccountID" = "Extent2"."AccountID" 
      AND "Extent1"."TriggerID" = "Extent2"."Id" 
      AND "Extent3"."AccountID" = "Extent2"."AccountID" 
      AND "Extent3"."TriggerID" = "Extent2"."Id" 
    WHERE 
      1 = "Extent2"."TriggerType" 
      AND "Extent1"."Failed" != TRUE 
      AND 0 = "Extent1"."InheritanceBehavior" 
      AND "Extent3"."TimeSpanInSeconds" IS NOT NULL 
      AND "Extent1"."DateApplied" + CAST (
        "Extent3"."TimeSpanInSeconds" / 31556952 :: int8 AS int4
      ) * INTERVAL '1 Years' + CAST (
        "Extent3"."TimeSpanInSeconds" - "Extent3"."TimeSpanInSeconds" / 31556952 :: int8 * 31556952 :: int8 AS int4
      ) * INTERVAL '1 Seconds' < CAST (
        CURRENT_TIMESTAMP AT TIME ZONE 'UTC' AS timestamp
      )
  ) AS "Join2" 
  LEFT OUTER JOIN "public"."DbNodes" AS "Extent4" ON "Join2"."NodeID" = "Extent4"."Id" 
  AND "Join2"."AccountID" = "Extent4"."AccountID" 
WHERE 
  1 = "Extent4"."SystemType" 
  OR 4 = "Extent4"."SystemType" 
  OR 5 = "Extent4"."SystemType" 
  OR 6 = "Extent4"."SystemType" 
  OR 7 = "Extent4"."SystemType" 
  OR 18 = "Extent4"."SystemType"