Index: openacs-4/packages/acs-kernel/sql/postgresql/postgresql.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/postgresql/postgresql.sql,v
diff -u -r1.14 -r1.15
--- openacs-4/packages/acs-kernel/sql/postgresql/postgresql.sql	15 Sep 2001 00:32:45 -0000	1.14
+++ openacs-4/packages/acs-kernel/sql/postgresql/postgresql.sql	29 Nov 2001 22:19:47 -0000	1.15
@@ -41,7 +41,7 @@
 
         return 0;
 
-end;' language 'plpgsql';
+end;' language 'plpgsql' with (iscachable);
 
 
 create function instr(varchar,char,integer) returns integer as '
@@ -51,7 +51,7 @@
         dir             alias for $3;
 begin
         return instr(str,pat,dir,1);
-end;' language 'plpgsql';
+end;' language 'plpgsql' with (iscachable);
 
 
 create function instr(varchar,char) returns integer as '
@@ -60,7 +60,7 @@
         pat             alias for $2;
 begin
         return instr(str,pat,1,1);
-end;' language 'plpgsql';
+end;' language 'plpgsql' with (iscachable);
 
 
 -- Splits string on requested character. Returns requested element
@@ -94,7 +94,7 @@
     return null;
   end if;
   return substr(p_string, v_left_split+1, (v_right_split - v_left_split - 1));
-end;' language 'plpgsql';
+end;' language 'plpgsql' with (iscachable);
 
 
 create function get_func_drop_command (varchar) returns varchar as '
@@ -194,7 +194,7 @@
 
         return v_ret || rpad(v_cnt,10) || v_tmp;
 
-end;' language 'plpgsql';
+end;' language 'plpgsql' with (iscachable);
 
 create function get_func_definition (varchar,oidvector) returns text as '
 declare
@@ -445,7 +445,7 @@
 create function tree_default_encoding_base() returns integer as '
 begin
         return 159;
-end;' language 'plpgsql';
+end;' language 'plpgsql' with (iscachable);
 
 create function tree_next_key(varchar) returns varchar as '
 declare
@@ -511,9 +511,31 @@
 
         return cnt;
 
-end;' language 'plpgsql';
+end;' language 'plpgsql' with (iscachable);
 
+-- DRB: Use tree_left() and tree_right() to do selects against
+-- tree_sortkey.
 
+-- To find a node's children in "t":
+-- tree_sortkey between tree_left(t.tree_sortkey) and tree_right(t.tree_sortkey)
+
+-- To get the children and the node (i.e. the subtree starting with the node):
+-- tree_sortkey between t.tree_sortkey and tree_right(t.tree_sortkey)
+
+create function tree_left(varchar) returns varchar as '
+declare
+  p_tree_sortkey alias for $1;
+begin
+  return p_tree_sortkey;
+end;' language 'plpgsql' with (iscachable);
+
+create function tree_right(varchar) returns varchar as '
+declare
+  p_tree_sortkey alias for $1;
+begin
+  return p_tree_sortkey || chr(255);
+end;' language 'plpgsql' with (iscachable);
+
 -- PG substitute for Oracle user_tab_columns view
 
 create view user_tab_columns as
@@ -644,5 +666,5 @@
 
  return description;
 
-end;' language 'plpgsql';
+end;' language 'plpgsql' with (iscachable);
 
