18 | | SELECT chemin from rht.rht_topology where chemin <@ '212340'; -- tronçon source de la Vilaine -- 2360 |
| 18 | SELECT * from rht.rht_topology where chemin <@ '212340'; -- tronçon source de la Vilaine -- 2360 |
| 19 | SELECT chemin from rht.rht_topology where chemin <@ '212340' limit 1 |
| 20 | -- La distance source est la distance mer maximale de tous les chemins possibles en ne prenant que le dernier tronçon du chemin. |
| 21 | Select max(dmer) from rht.rht_topology where id_drain in ( |
| 22 | Select cast(ltree2text(subpath(chemin, -1, 1))as integer) as chenin_id_drain from rht.rht_topology where chemin <@ '212340'); |
| 23 | |
| 24 | -- fonction pour renvoyer les distances source |
| 25 | DROP FUNCTION IF EXISTS rht.distance_source(); |
| 26 | CREATE OR REPLACE FUNCTION rht.distance_source() RETURNS integer AS $$ |
| 27 | DECLARE |
| 28 | id_drains RECORD; |
| 29 | nbligne integer; |
| 30 | BEGIN |
| 31 | nbligne:=1; |
| 32 | DROP TABLE IF EXISTS rht.distance_mer; |
| 33 | CREATE TABLE rht.distance_mer (id_drain integer,distance_mer numeric); |
| 34 | FOR id_drains IN SELECT id_drain FROM rht.rht_topology ORDER BY id_drain LOOP |
| 35 | -- pour vérification décommenter ensuite |
| 36 | RAISE NOTICE 'distance_source for %', quote_ident(CAST(id_drains.id_drain as text)); |
| 37 | EXECUTE 'INSERT INTO rht.distance_mer SELECT MAX(dmer) FROM rht.rht_topology WHERE id_drain IN ( |
| 38 | SELECT CAST(ltree2text(subpath(chemin, -1, 1))as integer) FROM rht.rht_topology where chemin <@ text2ltree(cast ('|| |
| 39 | id_drains.id_drain |
| 40 | || 'as text)) )'; |
| 41 | nbligne=nbligne+1; |
| 42 | END LOOP; |
| 43 | RETURN nbligne; |
| 44 | END; |
| 45 | $$ LANGUAGE plpgsql; |
| 46 | |
| 47 | select rht.distance_source(); |