Select your cookie preferences

We use essential cookies and similar tools that are necessary to provide our site and services. We use performance cookies to collect anonymous statistics, so we can understand how customers use our site and make improvements. Essential cookies cannot be deactivated, but you can choose “Customize” or “Decline” to decline performance cookies.

If you agree, AWS and approved third parties will also use cookies to provide useful site features, remember your preferences, and display relevant content, including relevant advertising. To accept or decline all non-essential cookies, choose “Accept” or “Decline.” To make more detailed choices, choose “Customize.”

REVERSE function

Focus mode
REVERSE function - Amazon Redshift

The REVERSE function operates on a string and returns the characters in reverse order. For example, reverse('abcde') returns edcba. This function works on numeric and date data types as well as character data types; however, in most cases it has practical value for character strings.

Syntax

REVERSE( expression )

Argument

expression

An expression with a character, date, timestamp, or numeric data type that represents the target of the character reversal. All expressions are implicitly converted to VARCHAR strings. Trailing blanks in CHAR strings are ignored.

Return type

VARCHAR

Examples

The following examples use data from the USERS and SALES tables in the TICKIT sample database. For more information, see Sample database.

To select five distinct city names and their corresponding reversed names from the USERS table, use the following example.

SELECT DISTINCT city AS cityname, REVERSE(cityname) FROM users ORDER BY city LIMIT 5; +----------+----------+ | cityname | reverse | +----------+----------+ | Aberdeen | needrebA | | Abilene | enelibA | | Ada | adA | | Agat | tagA | | Agawam | mawagA | +----------+----------+

To select five sales IDs and their corresponding reversed IDs cast as character strings, use the following example.

SELECT salesid, REVERSE(salesid) FROM sales ORDER BY salesid DESC LIMIT 5; +---------+---------+ | salesid | reverse | +---------+---------+ | 172456 | 654271 | | 172455 | 554271 | | 172454 | 454271 | | 172453 | 354271 | | 172452 | 254271 | +---------+---------+

On this page

PrivacySite termsCookie preferences
© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved.