Do

형식

DO $$DECLARE
    [변수 선언]
BEGIN
    [본문]
END$$;

예제

-- 1 --
DO $$DECLARE
BEGIN
EXECUTE FORMAT('COPY RC_BLD_BULD FROM ''/docker-entrypoint-initdb.d/raw/%s.csv''
               WITH DELIMITER E''|'' ENCODING ''utf-8''', 'org_RC_BLD_BULD_11__202209');
END$$;

-- 2 --
DO $$DECLARE
    r record;
BEGIN
    FOR r IN SELECT table_schema, table_name FROM information_schema.tables
             WHERE table_type = 'VIEW' AND table_schema = 'public'
    LOOP
        EXECUTE 'GRANT ALL ON ' || quote_ident(r.table_schema) || '.' || quote_ident(r.table_name) || ' TO webuser';
    END LOOP;
END$$;