Skip to content

Instantly share code, notes, and snippets.

@mauricioprado00
Last active September 10, 2016 21:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mauricioprado00/6aaaa18d750a6ffe52ea6567301fed6f to your computer and use it in GitHub Desktop.
Save mauricioprado00/6aaaa18d750a6ffe52ea6567301fed6f to your computer and use it in GitHub Desktop.
dinamically reading tables postgresql
create function test(tablename text) RETURNS void as $$
DECLARE
r text;
BEGIN
raise notice 'reading from: %', tablename;
FOR r IN execute ('SELECT sid FROM ' || tablename)
LOOP
-- can do some processing here
raise notice 'sid readed: %', r;
END LOOP;
END;
$$ LANGUAGE plpgsql;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment