string functions : substr_start and reverse_str

From: "PG Explorer" <pgmail(at)pgexplorer(dot)com>
To: <pgsql-novice(at)postgresql(dot)org>, "April L" <april(at)i-netco(dot)com>
Subject: string functions : substr_start and reverse_str
Date: 2002-04-14 17:51:10
Message-ID: 001501c1e3dc$f74e5220$c80ba8c0@sabex.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Took me 10 min to complete

CREATE FUNCTION substr_start(varchar,varchar,int4) RETURNS varchar AS '
DECLARE
original alias for $1;
substring alias for $2;
startpoint alias for $3;
return_str varchar;
BEGIN
return strpos(substr(original,startpoint,length(original)),substring);
END;'
LANGUAGE 'plpgsql'

CREATE FUNCTION reverse_str(varchar) RETURNS varchar AS '
DECLARE
original alias for $1;
reverse_str varchar;
i int4;
BEGIN
reverse_str = '''';
FOR i IN REVERSE LENGTH(original)..1 LOOP
reverse_str = reverse_str || substr(original,i,1);
END LOOP;
return reverse_str;
END;'
LANGUAGE 'plpgsql';

http://www.pgexplorer.com
GUI postgresql tool

----- Original Message -----
From: "April L" <april(at)i-netco(dot)com>
To: <pgsql-novice(at)postgresql(dot)org>
Sent: Sunday, April 14, 2002 7:02 PM
Subject: [NOVICE] string functions

> I have studied the Users Lounge and links off of it, looking for a place
> where PG users are sharing extended functions they have created for PG.
>
> In particular I am looking for string functions such as being able to
> specify a start point for finding a substring within a string. The
existing
> PGSQL function position(substring,string) nor strpos(string,substring)
have
> the option of specifying a start point for the search.
>
> Also I am looking for a function to reverse a string, so that for example
> reverse("april") returns "lirpa"
>
> Can anyone point me to an area where users are sharing functions they
> created, especially the ones I'm looking for? At this point I'm not able
to
> write one for myself. I am stuck using Cold Fusion which does include the
> functions I need, but is so slow at it that it times out before completing
> the update to all of my 250,000 records.
>
> Thank you,
>
> - April
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
> (send "unregister YourEmailAddressHere" to majordomo(at)postgresql(dot)org)

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Josh Berkus 2002-04-14 18:25:46 Re: migration still a problem
Previous Message April L 2002-04-14 17:02:11 string functions