Skip to content

Instantly share code, notes, and snippets.

@nuklea
Last active August 29, 2015 14:23
Show Gist options
  • Save nuklea/0c4e05d86ffa6aaed93b to your computer and use it in GitHub Desktop.
Save nuklea/0c4e05d86ffa6aaed93b to your computer and use it in GitHub Desktop.
Dynamic table name in query
DO $$
DECLARE
r record;
BEGIN
FOR r IN SELECT tablename FROM pg_catalog.pg_tables WHERE tablename LIKE 'schema_%%' LOOP
EXECUTE 'UPDATE ' || quote_ident(r.tablename) || ' SET host_added = ''54auto.ru'' WHERE host_added = ''54.ruauto.ru''';
END LOOP;
END $$ LANGUAGE plpgsql;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment