Skip to content

Instantly share code, notes, and snippets.

@nuklea
Last active Aug 29, 2015
Embed
What would you like to do?
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