Mercurial > gemma
annotate schema/updates/1101/01.improve_del_import.sql @ 4385:610773d34e4f
hydrological_conditions: decouple diagram from dialogue
author | Thomas Junk <thomas.junk@intevation.de> |
---|---|
date | Thu, 12 Sep 2019 15:06:53 +0200 |
parents | 52f7264265bb |
children |
rev | line source |
---|---|
4126
52f7264265bb
Bulk-delete tracked entries per table
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
1 CREATE OR REPLACE FUNCTION import.del_import(imp_id int) RETURNS void AS |
52f7264265bb
Bulk-delete tracked entries per table
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
2 $$ |
52f7264265bb
Bulk-delete tracked entries per table
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
3 DECLARE |
52f7264265bb
Bulk-delete tracked entries per table
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
4 tmp RECORD; |
52f7264265bb
Bulk-delete tracked entries per table
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
5 BEGIN |
52f7264265bb
Bulk-delete tracked entries per table
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
6 FOR tmp IN |
52f7264265bb
Bulk-delete tracked entries per table
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
7 SELECT relation, array_agg(key) AS keys |
52f7264265bb
Bulk-delete tracked entries per table
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
8 FROM import.track_imports |
52f7264265bb
Bulk-delete tracked entries per table
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
9 WHERE import_id = imp_id AND NOT deletion |
52f7264265bb
Bulk-delete tracked entries per table
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
10 GROUP BY relation |
52f7264265bb
Bulk-delete tracked entries per table
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
11 LOOP |
52f7264265bb
Bulk-delete tracked entries per table
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
12 EXECUTE format('DELETE FROM %s WHERE id = ANY($1)', tmp.relation) |
52f7264265bb
Bulk-delete tracked entries per table
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
13 USING tmp.keys; |
52f7264265bb
Bulk-delete tracked entries per table
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
14 END LOOP; |
52f7264265bb
Bulk-delete tracked entries per table
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
15 END; |
52f7264265bb
Bulk-delete tracked entries per table
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
16 $$ |
52f7264265bb
Bulk-delete tracked entries per table
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
17 LANGUAGE plpgsql; |