Explorar o código

commit inicial

Rodney Enciso Arias %!s(int64=7) %!d(string=hai) anos
achega
0183017be9
Modificáronse 1 ficheiros con 19 adicións e 0 borrados
  1. 19 0
      funcion de normalizacion de secuencia.txt

+ 19 - 0
funcion de normalizacion de secuencia.txt

@@ -0,0 +1,19 @@
+CREATE OR REPLACE FUNCTION normalize_seq() RETURNS VOID AS $$
+DECLARE
+statements CURSOR FOR
+SELECT '''' || relname || '''' as seqname,substring(relname from 1 for (char_length(relname) -7)) as tablename 
+FROM pg_class 
+WHERE relkind  = 'S' and
+relname in
+(select table_name||'_id_seq'
+from information_schema.columns 
+where table_catalog = 'golden_24_10' and table_schema = 'public' and column_name = 'id');
+BEGIN
+FOR smt IN statements LOOP
+RAISE NOTICE 'Secuencia actualizada: %',smt.seqname;
+EXECUTE 'select pg_catalog.setval(' || smt.seqname || ', (select max(id)+1 from ' || smt.tablename || '), true)';
+END LOOP;
+END;
+$$ LANGUAGE PLPGSQL;
+
+SELECT normalize_seq();