incubator-empire-db-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Frank Lupo <frank_l...@email.it>
Subject reverse function in postgresql
Date Thu, 02 Jul 2009 15:39:27 GMT
Hi all,
in postgreql the reverse function not exist.
Is posible create function reverse when connect to db?

thanks

=====================================================
CREATE OR REPLACE FUNCTION reverse(TEXT) RETURNS TEXT AS '
   DECLARE
      original ALIAS FOR $1;
      reversed TEXT := \'\';
      onechar  VARCHAR;
      mypos    INTEGER;
   BEGIN
      SELECT LENGTH(original) INTO mypos;
      LOOP
         EXIT WHEN mypos < 1;
         SELECT substring(original FROM mypos FOR 1) INTO onechar;
         reversed := reversed || onechar;
         mypos := mypos -1;
      END LOOP;
      RETURN reversed;
   END
' LANGUAGE plpgsql IMMUTABLE RETURNS NULL ON NULL INPUT;

=====================================================
CREATE OR REPLACE FUNCTION reverse(TEXT) RETURNS TEXT AS '
  DECLARE
    original ALIAS FOR $1;
    reversed TEXT := \'\';
    onechar  VARCHAR;
    mypos    INTEGER;
  BEGIN
    SELECT LENGTH(original) INTO mypos;
    LOOP
      EXIT WHEN mypos < 1;
      SELECT substring(original FROM mypos FOR 1) INTO onechar;
      reversed := reversed || onechar;
      mypos := mypos -1;
    END LOOP;
    RETURN reversed;
  END
' LANGUAGE plpgsql IMMUTABLE RETURNS NULL ON NULL INPUT;
=====================================================
create or replace function reverse_string(text) returns text as
'
DECLARE
reversed_string text;
incoming alias for $1;

BEGIN

reversed_string = '''';

for i in reverse char_length(incoming)..1 loop
  reversed_string = reversed_string || substring(incoming from i for 1);
end loop;

return reversed_string;
END'
language plpgsql;


 
 
 --
 Caselle da 1GB, trasmetti allegati fino a 3GB e in piu' IMAP, POP3 e SMTP autenticato? GRATIS
solo con Email.it http://www.email.it/f
 
 Sponsor:
 Se ci racconti i tuoi gesti d'amore per il tuo cane, Cesar ti premia. Partecipa anche tu!
 Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid=9205&d=2-7

Mime
View raw message