REVERSE

Returns a reversed order of a character string.

Syntax

REVERSE( expr )

Arguments

Parameter

Description

expr

String expression

Returns

Returns the same type as the argument supplied.

Notes

  • If the value is NULL, the result is NULL.

Examples

For these examples, consider the following table and contents:

CREATE TABLE jabberwocky(line TEXT);

INSERT INTO jabberwocky VALUES
   ('''Twas brillig, and the slithy toves '), ('      Did gyre and gimble in the wabe: ')
   ,('All mimsy were the borogoves, '), ('      And the mome raths outgrabe. ')
   ,('"Beware the Jabberwock, my son! '), ('      The jaws that bite, the claws that catch! ')
   ,('Beware the Jubjub bird, and shun '), ('      The frumious Bandersnatch!" ');

Using REVERSE

t=> SELECT line, REVERSE(line) FROM jabberwocky;
line                                             | reverse
-------------------------------------------------+-------------------------------------------------
'Twas brillig, and the slithy toves              |  sevot yhtils eht dna ,gillirb sawT'
      Did gyre and gimble in the wabe:           |  :ebaw eht ni elbmig dna eryg diD
All mimsy were the borogoves,                    |  ,sevogorob eht erew ysmim llA
      And the mome raths outgrabe.               |  .ebargtuo shtar emom eht dnA
"Beware the Jabberwock, my son!                  |  !nos ym ,kcowrebbaJ eht eraweB"
      The jaws that bite, the claws that catch!  |  !hctac taht swalc eht ,etib taht swaj ehT
Beware the Jubjub bird, and shun                 |  nuhs dna ,drib bujbuJ eht eraweB
      The frumious Bandersnatch!"                |  "!hctansrednaB suoimurf ehT