On Tue, Sep 27, 2011 at 13:00, Harald Fuchs <hari.fuchs@xxxxxxxxx> wrote: > Pavel Stehule has found a better solution for that: > > CREATE OR REPLACE FUNCTION reverse(text) RETURNS text AS $$ > SELECT string_agg(substring($1 FROM i FOR 1), '') > FROM generate_series(length($1), 1, -1) g(i) > $$ language sql; I don't want to get into a pissing contest, but I'm not sure by which criteria this is "better". When I needed this function, I compared the speed many different approaches (6 different versions from the mailing lists). The one I posted above was the winner, a slightly tuned version of the original by Shoaib Mir. When testing this right now, it takes half the time of the function you posted, for short non-Unicode strings at least. Regards, Marti -- Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general