Index: openacs-4/packages/acs-kernel/sql/postgresql/site-nodes-create.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/postgresql/site-nodes-create.sql,v
diff -u -r1.26 -r1.27
--- openacs-4/packages/acs-kernel/sql/postgresql/site-nodes-create.sql	2 Apr 2013 11:05:17 -0000	1.26
+++ openacs-4/packages/acs-kernel/sql/postgresql/site-nodes-create.sql	23 Apr 2013 15:23:11 -0000	1.27
@@ -434,32 +434,81 @@
 
 -- function url
 
-
 -- added
 select define_function_args('site_node__url','node_id');
 
 --
 -- procedure site_node__url/1
 --
-CREATE OR REPLACE FUNCTION site_node__url(
-   url__node_id integer
-) RETURNS varchar AS $$
+
+CREATE FUNCTION inline_0()
+RETURNS integer AS $inline_0$
 BEGIN
-    return ( With RECURSIVE site_nodes_recursion(parent_id, path, directory_p, node_id) as (
+
+    raise notice 'starting site-nodes doing the recursive part -- vguerra';
+
+    IF cmp_pg_version('8.4') >= 0 THEN
+        -- recursive site_nodes recursive - START
+
+        CREATE OR REPLACE FUNCTION site_node__url(
+           url__node_id integer
+        ) RETURNS varchar AS $$
+        BEGIN
+            return ( With RECURSIVE site_nodes_recursion(parent_id, path, directory_p, node_id) as (
+            
+                select parent_id, ARRAY[name || case when directory_p then '/' else ' ' end]::text[] as path, directory_p, node_id
+                from site_nodes where node_id = url__node_id
+            
+                UNION ALL
+            
+                select sn.parent_id, sn.name::text || snr.path , sn.directory_p, snr.parent_id
+                from site_nodes sn join site_nodes_recursion snr on sn.node_id = snr.parent_id 
+                where snr.parent_id is not null    
+
+            ) select array_to_string(path,'/') from site_nodes_recursion where parent_id is null
+        );
+        END; 
+        $$ LANGUAGE plpgsql; 
+
+        -- recursive site_nodes END
     
-        select parent_id, ARRAY[name || case when directory_p then '/' else ' ' end]::text[] as path, directory_p, node_id
-        from site_nodes where node_id = url__node_id
+    ELSE
+
+        CREATE OR REPLACE FUNCTION site_node__url(
+           url__node_id integer
+        ) RETURNS varchar AS $$
+        DECLARE
+          v_parent_id            site_nodes.node_id%TYPE;
+          v_name                 site_nodes.name%TYPE;
+          v_directory_p          site_nodes.directory_p%TYPE;
+        BEGIN
+            if url__node_id is null then
+              return '';
+            end if;
+
+            select parent_id, name, directory_p into
+                   v_parent_id, v_name, v_directory_p
+            from site_nodes
+            where node_id = url__node_id;
+
+            if v_directory_p = 't' then
+              return site_node__url(v_parent_id) || v_name || '/';
+            else
+              return site_node__url(v_parent_id) || v_name;
+            end if;
+           
+        END;
+        $$ LANGUAGE plpgsql;
+
+    END IF;
     
-        UNION ALL
-    
-        select sn.parent_id, sn.name::text || snr.path , sn.directory_p, snr.parent_id
-        from site_nodes sn join site_nodes_recursion snr on sn.node_id = snr.parent_id 
-        where snr.parent_id is not null    
+    raise notice 'done doing the recursive part -- vguerra';
 
-    ) select array_to_string(path,'/') from site_nodes_recursion where parent_id is null
-);
+    return null;
 END; 
-$$ LANGUAGE plpgsql; 
+$inline_0$ LANGUAGE plpgsql;
 
+select inline_0();
+drop function inline_0();
 
 -- show errors
