CREATE OR REPLACE VIEW sequence_setvals AS 
 SELECT ((((('SELECT setval(''"' || cs.relname) || '"'', max("') || a.attname) || '")) FROM
"') || c.relname) || '";' AS expr
   FROM pg_class c, pg_class cs, pg_attribute a, pg_attrdef d
  WHERE cs.relkind = 'S' AND d.adsrc LIKE (('%''' || cs.relname) || '''%')  AND c.oid = a.attrelid AND c.oid = d.adrelid AND d.adnum = a.attnum;
