How do I write a Postgres SQL command based on metadata of the tables themselves?
Postgres 9.5 introduced a feature to record commit timestamps. The documentation:


  track_commit_timestamp (bool)
  
  Record commit time of transactions. This parameter can only be set in
  postgresql.conf file or on the server command line. The default value
  is off.


And functions to work with it.

Once you have activated the setting and restarted the DB server, Postgres starts tracking commit timestamps. Then, for example, to get all rows from a table that were changed in any way during the last 4 hours:

SELECT * FROM tbl
WHERE  pg_xact_commit_timestamp(xmin) &gt;= now() - interval '4 hours';


Related:


How list all tables with data changes in the last 24 hours?
Atomically set SERIAL value when committing transaction