Literals

Description

A literal or constant is a fixed data value, composed of a sequence of characters or a numeric constant. (Redshift SQL Language reference Literals).

Amazon Redshift supports several types of literals, including:

  • Numeric literals for integer, decimal, and floating-point numbers.

  • Character literals, also referred to as strings, character strings, or character constants.

  • Datetime and interval literals, used with datetime data types.

Sample Source Patterns

Input Code:

IN -> Redshift_01.sql
-- Number literals.
SELECT 42 AS integer_literal, -- Simple integer
    -123 AS negative_integer, -- Negative integer
    3.14159 AS decimal_literal, -- Decimal number
    1E0 AS simple_float; -- Floating-point representation of 1

-- Character literals.   
SELECT 'Hello, World!' AS simple_string,
    'Line1\nLine2' AS newline_character, -- Interprets \n as literal
    'Tab\tCharacter' AS tab_character, -- Interprets \t as literal
    'The value is ' || 42 AS mixed_literal;

Output Code:

OUT -> Redshift_01.sql
-- Number literals.
SELECT 42 AS integer_literal, -- Simple integer
    -123 AS negative_integer, -- Negative integer
    3.14159 AS decimal_literal, -- Decimal number
    1E0 AS simple_float; -- Floating-point representation of 1

-- Character literals.   
SELECT 'Hello, World!' AS simple_string,
    'Line1\nLine2' AS newline_character, -- Interprets \n as literal
    'Tab\tCharacter' AS tab_character, -- Interprets \t as literal
    'The value is ' || 42 AS mixed_literal;

Know Issues

This functionality is not currently supported in Snowflake, but it will be supported through a future migration.

select $MyTagForLiteral$
This is
a test
of a tag literal
$MyTagForLiteral$ as c1;

There are no known issues.

Last updated