Changes between Initial Version and Version 1 of Recursive


Ignore:
Timestamp:
Jun 1, 2012 4:26:17 PM (13 years ago)
Author:
cedric
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Recursive

    v1 v1  
     1{{{ 
     2#!sql 
     3CREATE FUNCTION rht.abondance_amont(integer) RETURNS integer AS 
     4$fonction$ 
     5                WITH parcours(id_drain, abondance_amont) AS 
     6                ( 
     7                               WITH RECURSIVE parcours(id_drain, abondance_amont) AS 
     8                              ( 
     9                                               SELECT id_drain, abondance FROM rht.crosstab_rhtvs2 WHERE id_drain = $1 
     10 
     11                                               UNION 
     12 
     13                                               SELECT crosstab_rhtvs2.id_drain, crosstab_rhtvs2.abondance FROM rht.crosstab_rhtvs2, parcours  
     14                                               JOIN rht.crosstab_rhtvs2 AS t1  
     15                                               ON parcours.id_drain =  t1.id_drain  
     16                                               WHERE ST_Intersects(ST_Line_Interpolate_Point(t1.the_geom, 0), ST_Line_Interpolate_Point(crosstab_rhtvs2.the_geom, 1))  
     17                                               AND t1.the_geom && crosstab_rhtvs2.the_geom  
     18                                               AND t1.exutoire = crosstab_rhtvs2.exutoire 
     19                               ) SELECT DISTINCT id_drain, abondance_amont  FROM parcours 
     20                ) SELECT ROUND(SUM(abondance_amont))::integer  FROM parcours; 
     21$fonction$ 
     22LANGUAGE SQL STABLE; 
     23}}}