Monday, July 24. 2006Reverse a text in PostgreSQLTrackbacks
Trackback specific URI for this entry
No Trackbacks
Comments
Display comments as
(Linear | Threaded)
Using recursion, one can also achieve it with a plain sql function:
create function reverse(text) returns text as $$
select case when length($1)>0
then substring($1, length($1), 1) || reverse(substring($1, 1, length($1)-1))
else '' end $$ language sql immutable strict;
Comments ()
a code from Varlena is not good - there is a few issues - first issue is using a WHILE statement. FOR statement is better - is faster. And you can use a simple and relative fast SQL function
create or replace function rvrs(text)
returns text as $$
select string_agg(substring($1 from i for 1),'')
from generate_series(length($1),1,-1) g(i)
$$ language sql;
Comments ()
Here is one more function to reverse text that uses FOR statement if anybody interested.
create or replace function rev(varchar) returns varchar as $$
declare
_temp varchar;
_count int;
begin
_temp := '';
for _count in reverse length($1)..1 loop
_temp := _temp || substring($1 from _count for 1);
end loop;
return _temp;
end;
$$ language plpgsql immutable;
Comments ()
|
QuicksearchBlog AdministrationPostgreSQL BuchCalendar
BookmarksCategoriesLast SearchStatisticsLast entry: 2019-02-03 14:34
957 entries written
568 comments have been made
26064 visitor(s) this month
335 visitor(s) today
141 visitor(s) online
Top Referersprohoster.info (122445)
sex-tale.ru (49738) xxx-rasskaz.ru (47335) vk.com (30105) blogos.kz (30103) ua.tc (30015) newporno.xyz (26737) blox.ua (25371) 2dm.prohoster.info (24280) link.ac (22459) Recent Entries
Archives |