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.”

LEFT and RIGHT functions

Focus mode
LEFT and RIGHT functions - Amazon Redshift

These functions return the specified number of leftmost or rightmost characters from a character string.

The number is based on the number of characters, not bytes, so that multibyte characters are counted as single characters.

Syntax

LEFT( string, integer ) RIGHT( string, integer )

Arguments

string

A CHAR string, a VARCHAR string, or any expression that evaluates to a CHAR or VARCHAR string.

integer

A positive integer.

Return type

VARCHAR

Examples

The following example uses data from the EVENT table in the TICKIT sample database. For more information, see Sample database.

To return the leftmost 5 and rightmost 5 characters from event names that have event IDs between 1000 and 1005, use the following example.

SELECT eventid, eventname, LEFT(eventname,5) AS left_5, RIGHT(eventname,5) AS right_5 FROM event WHERE eventid BETWEEN 1000 AND 1005 ORDER BY 1; +---------+----------------+--------+---------+ | eventid | eventname | left_5 | right_5 | +---------+----------------+--------+---------+ | 1000 | Gypsy | Gypsy | Gypsy | | 1001 | Chicago | Chica | icago | | 1002 | The King and I | The K | and I | | 1003 | Pal Joey | Pal J | Joey | | 1004 | Grease | Greas | rease | | 1005 | Chicago | Chica | icago | +---------+----------------+--------+---------+

On this page

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