github.com/supabase/cli@v1.168.1/internal/utils/parser/testdata/split_14.sql (about)

     1  
     2  
     3  CREATE OR REPLACE FUNCTION "blocks".delete_orphaned_blocks()
     4      RETURNS TRIGGER
     5  AS $$
     6  BEGIN
     7      LOOP
     8          -- Note that RETURN QUERY does not return from the function - it works
     9          -- more like the yield-statement in PHP, in that records from the
    10          -- DELETE..RETURNING statement are returned, and execution then
    11          -- resumes from the following statement.
    12  
    13          DELETE FROM "blocks"."block" b
    14          WHERE b.uuid IN (
    15              SELECT c.block_uuid
    16              FROM "blocks"."block_count" c
    17              WHERE c.ref_count = 0 AND c.user_count = 0
    18          );
    19  
    20          -- The FOUND flag is set TRUE/FALSE after executing a query - so we
    21          -- EXIT from the LOOP block when the DELETE..RETURNING statement does
    22          -- not delete and return any records.
    23  
    24          EXIT WHEN NOT FOUND;
    25      END LOOP;
    26  
    27      RETURN NULL;
    28  END;
    29  $$
    30  LANGUAGE plpgsql;