Permalink
Browse files

fix postgres sequences snippet

  • Loading branch information...
1 parent 38a5d4f commit 8930305bc16374a17a419eb390ed329e7cf7e089 Lance Caraccioli committed Apr 11, 2012
Showing with 4 additions and 0 deletions.
  1. +4 −0 fix-sequences.sql
View
@@ -0,0 +1,4 @@
+--running this script will generate sql which will fix broken sequences for a postgres database... (tested on postgres 8.4)
+
+select 'SELECT setval('''||ns.nspname||'.'||cs.relname||''', max("'||attname||'")) FROM "'||ns.nspname||'"."'||c.relname||'";' from pg_class c, pg_class cs, pg_attribute a, pg_attrdef d, pg_namespace ns where c.relnamespace = ns.oid and cs.relkind = 'S' and d.adsrc ~ cs.relname and c.oid = a.attrelid and c.oid = d.adrelid and d.adnum = a.attnum;
+

0 comments on commit 8930305

Please sign in to comment.