What is REVERSE() function in Snowflake ?

Are you looking to find what is the REVERSE() function within the Snowflake cloud data warehouse or maybe you are looking for a solution how to use the reverse functions in the Snowflake? Or may be you are looking for How to reverse a string in Snowflake. If you are looking for any of these problem solutions then you have landed on the correct page. I will also show you what and how to use REVERSE() function. I will explain the REVERSE() function by taking a practical examples. So don’t waste time let’s start step by step guide to understanding what is the REVERSE() expression.

What is REVERSE() Function ?

REVERSE() function is used to build a string or binary value by reversing the given input order. The length of the given input value and returned value will be same, but the order is reversed. If the input value is NULL then the resultant output value will also be NULL.

Syntax of the Reverse function in Snowflake

-- Syntax : 

REVERSE( input)

REVERSE() Argument Details :

input parameterString value or Binary value ( Mandatory )
OutputString value in the reverse order

Input:

Here the input is the given input value that may be String or Binary as per the requirement.

How to reverse a string in Snowflake with Examples :

In order to reverse the string within the Snowflake, you can use the reverse function. This function has capability to reverse the whatever string you passed in the input parameter.

Example of Reverse string in Snowflake

--Example-1

select reverse('Hello, world');

+--------------------------+
| REVERSE('HELLO, WORLD!') |
|--------------------------|
|  dlrow ,olleH            |
+--------------------------+

As we can see the above example reversed the given string values (HELLO, WORLD).

--Example-2 :

select '2020-05-22'::date, reverse('2020-05-22'::date) as reversed;

+--------------------+------------+
| '2020-05-22'::DATE | REVERSED   |
|--------------------+------------|
| 2020-05-22         | 22-50-0202 |
+--------------------+------------+

As we can see the above example-2 which we got the reverse of the given date ‘2020-05-22’.

--Example-3 :

create table strings (s1 varchar collate 'eno', s2 varchar collate 'ahu');

insert into strings (s1, s2) values ('dzsa', collate('dzsa', 'ahu'));

select s1, s2, reverse(s1), reverse(s2) from strings;

+------+------+-------------+-------------+
| S1   | S2   | REVERSE(S1) | REVERSE(S2) |
|------+------+-------------+-------------|
| dzsa | dzsa | aszd        | aszd        |
+------+------+-------------+-------------+

Reverse Snowflake official Documentation Link

Final Thoughts

In this article we have learned about REVERSE() function and uses with the examples explained clearly. I have also covered different scenario with practical example that could be possible. I hope the information that was provided is helped in gaining the knowledge.

Please share your comments and suggestions in the comment section below and I will try to answer all your queries as time permits.

Unicode in Snowflake

Repeat function in Snowflake