update sequence conversion script

Поиск
Список
Период
Сортировка
От Sim Zacks
Тема update sequence conversion script
Дата
Msg-id 1381227955.20041011103903@compulab.co.il
обсуждение исходный текст
Ответы Re: update sequence conversion script
Список pgsql-general
I am in the process of converting an existing database to PostGreSQL
and wrote a generic script to update all of the sequences as they default at 1.
I thought it would be useful to other people who are converting their
databases.

If anyone can write this script in using plpythonu, I would love to
see how it is done.

create or replace function UpdateSequences() returns varchar(50) as
$$
declare
        seqrecord record;
        tblname varchar(50);
        fieldname varchar(50);
        maxrecord record;
        maxvalue integer;
begin
        for seqrecord in select relname from pg_statio_user_sequences Loop
                tblname:=split_part(seqrecord.relname,'_',1);
                fieldname:=split_part(seqrecord.relname,'_',2);
                for maxrecord in execute 'select max(' || fieldname || ') as f1 from ' || tblname LOOP
                        maxvalue:=maxrecord.f1;
                end loop;
                execute 'alter sequence ' || seqrecord.relname || ' restart with ' || coalesce(maxvalue,0)+1 ;
        End LOOP;
        return 1;
end
$$
 language plpgsql

Sim Zacks
IT Manager
CompuLab
04-829-0145 - Office
04-832-5251 - Fax


В списке pgsql-general по дате отправления:

Предыдущее
От: dom@happygiraffe.net (Dominic Mitchell)
Дата:
Сообщение: Re: Get Postgre Status and Information
Следующее
От: "Armen Rizal"
Дата:
Сообщение: Reusable pl/pgsql samples ?