Skip to content

Instantly share code, notes, and snippets.

@xtrmstep
Created November 27, 2023 10:58
Show Gist options
  • Save xtrmstep/e81d4545b697088d7d2e4f53cd5b7164 to your computer and use it in GitHub Desktop.
Save xtrmstep/e81d4545b697088d7d2e4f53cd5b7164 to your computer and use it in GitHub Desktop.
Shows several things about PostgreSQL: how to use multi-statement query in query window, output message and use metadata
DO
$do$
declare
r record;
query_cmd text;
begin
for r in select table_name from information_schema.tables where table_schema = 'public' and table_name like 'prefix%'
loop
query_cmd := format('delete from %s where CONDITION', r.table_name);
-- raise notice '%', query_cmd;
execute query_cmd;
end loop;
end
$do$;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment