string functions : substr_start and reverse_str

Поиск
Список
Период
Сортировка
От PG Explorer
Тема string functions : substr_start and reverse_str
Дата
Msg-id 001501c1e3dc$f74e5220$c80ba8c0@sabex.com
обсуждение исходный текст
Ответ на string functions  (April L <april@i-netco.com>)
Список 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@i-netco.com>
To: <pgsql-novice@postgresql.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@postgresql.org)


В списке pgsql-novice по дате отправления:

Предыдущее
От: April L
Дата:
Сообщение: string functions
Следующее
От: "Josh Berkus"
Дата:
Сообщение: Re: migration still a problem