/[openfoncier]/trunk/data/pgsql/update_sequences.sql
ViewVC logotype

Annotation of /trunk/data/pgsql/update_sequences.sql

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1804 - (hide annotations)
Tue Apr 30 14:45:17 2013 UTC (11 years, 9 months ago) by fmichon
File size: 1132 byte(s)
* Réorganisation des fichiers d'initialisation de la base de données.
=> Ajout d'un entête sur chaque fichier sql 
=> Ajout de la propriété svn:keywords Id

1 fmichon 1801 --------------------------------------------------------------------------------
2     -- Mise à jour des séquences avec le max + 1
3     --
4     -- @package openfoncier
5     -- @version SVN : $Id$
6     --------------------------------------------------------------------------------
7    
8     --
9     CREATE OR REPLACE FUNCTION fn_fixsequences() RETURNS integer AS
10     $BODY$
11     DECLARE
12     themax BIGINT;
13     mytables RECORD;
14     num integer;
15     BEGIN
16     num := 0;
17     FOR mytables IN
18     SELECT S.relname as seq, C.attname as attname, T.relname as relname
19     FROM pg_class AS S, pg_depend AS D, pg_class AS T, pg_attribute AS C
20     WHERE S.relkind = 'S'
21     AND S.oid = D.objid
22     AND D.refobjid = T.oid
23     AND D.refobjid = C.attrelid
24     AND D.refobjsubid = C.attnum
25     LOOP
26     EXECUTE 'SELECT MAX('||mytables.attname||') FROM '||mytables.relname||';' INTO themax;
27     IF (themax is null OR themax < 0) THEN
28     themax := 0;
29     END IF;
30     themax := themax +1;
31     EXECUTE 'ALTER SEQUENCE ' || mytables.seq || ' RESTART WITH '||themax;
32     num := num + 1;
33     END LOOP;
34    
35     RETURN num;
36    
37     END;
38     $BODY$
39     LANGUAGE 'plpgsql' VOLATILE;
40    
41     --
42     select fn_fixsequences();

Properties

Name Value
svn:keywords Id

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26