Recursive SQL functions - Mailing list pgsql-hackers

From Peter Eisentraut
Subject Recursive SQL functions
Date
Msg-id Pine.LNX.4.30.0110122157060.648-100000@peter.localdomain
Whole thread Raw
Responses Re: Recursive SQL functions
List pgsql-hackers
While looking to implement the ODBC replace() function (replace occurences
of $2 in $1 by $3), I found that it could be expressed as:

CREATE FUNCTION replace(text, text, text) RETURNS text AS '   select       case when position($2 in $1) = 0 or
char_length($2)= 0           then $1           else substring($1 from 1 for position($2 in $1) - 1)                ||
$3               || replace(substring($1 from position($2 in $1) + char_length($2)), $2, $3)       end;
 
' LANGUAGE SQL WITH (isstrict);

Now this command doesn't actually work because it requires the replace()
function to exist already.  But it does work if one first creates a stub
replace() function and then uses CREATE OR REPLACE.

(So much about the claim that procedural languages are a security hole
because they allow infinite loops.)

I was wondering whether, as a future project, we could make this more
convenient by parsing the body of the function with the binding of the
function already in effect.

Comments?

-- 
Peter Eisentraut   peter_e@gmx.net   http://funkturm.homeip.net/~peter



pgsql-hackers by date:

Previous
From: Bruce Momjian
Date:
Subject: Warning of OID wraparound
Next
From: Tom Lane
Date:
Subject: Re: Warning of OID wraparound