lexeme.sql 552 Bytes
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 INDEX leksemy_a_tergo ON leksemy (reverse(haslo));