Changes between Version 4 and Version 5 of Parcours source RHT


Ignore:
Timestamp:
Oct 26, 2011 12:12:03 PM (14 years ago)
Author:
cedric
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Parcours source RHT

    v4 v5  
    1818SELECT chemin from rht.rht_topology where chemin <@ '212340'; -- tronçon source de la Vilaine -- 2360 
    1919}}} 
     20== utilisation des donnees de parcours == 
     21En pratique nous n'aurons probablement besoin que du noeud le plus amont des parcours comme programmé ci dessus. Mais les scripts ci-dessous pourraient s'avérer utiles. 
     22{{{ 
     23 
     24/* 
     25regexp_split_to_array(string text, pattern text [, flags text ])        regexp_split_to_array('hello world', E'\\s+')   {hello,world} 
     26SELECT regexp_split_to_array('hello world', E'\\s+'); 
     27SELECT regexp_split_to_array('hello.world', E'\\.+'); 
     28*/ 
     29SELECT regexp_split_to_array(ltree2text(chemin),E'\\.+') from rht.rht_topology where chemin <@ '212340'; 
     30 
     31/* 
     32http://www.pgsql.cz/index.php/PostgreSQL_SQL_Tricks#Array_to_table 
     33SELECT (ARRAY[1,3,4,6,7])[idx.n] FROM generate_series(1,7) idx(n); 
     34CREATE OR REPLACE FUNCTION unpack(anyarray) 
     35RETURNS SETOF anyelement AS $$  
     36SELECT $1[i]  
     37   FROM generate_series(array_lower($1,1),  
     38                        array_upper($1,1)) g(i); 
     39$$ LANGUAGE sql STRICT IMMUTABLE; 
     40*/ 
     41CREATE OR REPLACE FUNCTION unpack(anyarray) 
     42RETURNS SETOF anyelement AS $$  
     43SELECT $1[i]  
     44   FROM generate_series(array_lower($1,1),  
     45                        array_upper($1,1)) g(i); 
     46$$ LANGUAGE sql STRICT IMMUTABLE; 
     47-- pour convertir un vecteur en table 
     48select unpack(vecteurchemin) from  
     49        (SELECT regexp_split_to_array(ltree2text(chemin),E'\\.+') as vecteurchemin from rht.rht_topology where chemin <@ '212340' limit 1) as sub 
     50-- j'avais pas vu il y a déjà une fonction magique unest... 
     51select cast(unnest(vecteurchemin) as integer) as chemin_id_drain from 
     52        (SELECT regexp_split_to_array(ltree2text(chemin),E'\\.+') as vecteurchemin from rht.rht_topology where chemin <@ '212340' limit 1) as sub 
     53-- Fonction qui renvoit les identifiants uniques des tronçons en amont d'un ouvrage 
     54 
     55 
     56CREATE OR REPLACE FUNCTION troncons(integer) 
     57RETURNS SETOF integer AS $$ 
     58select cast(unnest(vecteurchemin) as integer) as chemin_id_drain from 
     59        (SELECT regexp_split_to_array(ltree2text(chemin),E'\\.+') as vecteurchemin from rht.rht_topology where chemin <@ text2ltree(cast ($1 as text))  limit 1) as sub; 
     60$$ LANGUAGE sql STRICT IMMUTABLE;        
     61 
     62SELECT troncons_amont(212340); -- OK 
     63 
     64 
     65 
     66 
     67 
     68}}}