title: Create a function to get column from multiple tables in PostgreSQL
body: <p>I'm trying to create a function to get a field value from multiple tables in my database. I made script like this:</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION get_all_changes() RETURNS SETOF RECORD AS
  $$
  DECLARE 
    tblname VARCHAR;
    tblrow RECORD;
    row RECORD;
  BEGIN
      FOR tblrow IN SELECT tablename FROM pg_catalog.pg_tables WHERE schemaname='public' LOOP /*FOREACH tblname IN ARRAY $1 LOOP*/
        RAISE NOTICE 'r: %', tblrow.tablename;
        FOR row IN SELECT MAX("lastUpdate") FROM tblrow.tablename LOOP
            RETURN NEXT row;
        END LOOP;
      END LOOP;
  END
  $$
  LANGUAGE 'plpgsql' ;
  
  SELECT get_all_changes();
  </code></pre>
  
  <p>But it is not working, everytime it shows this error </p>
  
  <pre><code>tblrow.tablename" not defined in line "FOR row IN SELECT MAX("lastUpdate") FROM tblrow.tablename LOOP"
  </code></pre>