Skip to content

Literals

View as Markdown

A literal is a constant value written directly in a statement, such as 42, 'France' or DATE'2025-12-31'. This page shows how to write each kind and which data type it produces. The examples select from db_root, a system table with exactly one row.

  • An exact number is written with digits and an optional decimal point. It becomes an INTEGER, a BIGINT or a NUMERIC, depending on its size and whether it has decimals.
  • An approximate number uses scientific notation, with E followed by the power of 10. It becomes a DOUBLE.
  • A + or - sign can precede the number and the exponent.
SELECT TYPEOF(10), TYPEOF(123456789012), TYPEOF(1234234324234.23),
TYPEOF(1.2345E15), TYPEOF(-1.2345E-15)
FROM db_root;
typeof(10) typeof(123456789012) typeof(1234234324234.23) typeof(1.2345E15) typeof(-1.2345E-15)
integer bigint Numeric (15, 2) double double

Write the type name in front of a quoted string. The type name is not case-sensitive. With these literals you do not need conversion functions such as TO_DATE or TO_DATETIME.

Literal Accepted formats Example
DATE 'YYYY-MM-DD', 'MM/DD/YYYY' DATE'2025-12-31'
TIME 'HH:MI:SS', 'HH:MI:SS AM', 'HH:MI:SS PM' TIME'14:30:05'
DATETIME 'YYYY-MM-DD HH:MI:SS[.msec] [AM|PM]', 'MM/DD/YYYY HH:MI:SS[.msec] [AM|PM]' DATETIME'2025-12-31 14:30:05.123'
TIMESTAMP 'YYYY-MM-DD HH:MI:SS [AM|PM]', 'MM/DD/YYYY HH:MI:SS [AM|PM]' TIMESTAMP'2025-12-31 14:30:05'

msec is milliseconds, up to three digits.

SELECT DATE'2025-12-31', DATE'12/31/2025', TIME'02:30:05 PM',
DATETIME'12/31/2025 02:30:05.123 PM'
FROM db_root;
date '2025-12-31' date '12/31/2025' time '02:30:05 PM' datetime '12/31/2025 02:30:05.123 PM'
2025-12-31 2025-12-31 14:30:05 2025-12-31 14:30:05.123

The e-commerce examples throughout this manual use the ISO form, for example WHERE order_date >= DATE'2025-12-01'.

The time zone types take the same formats, followed by a time zone: an offset such as +02:00 or +02, or a region name such as Europe/Bucharest (see SHOW TIMEZONES).

Literal Same as Stores
DATETIMETZ'...' DATETIME WITH TIME ZONE '...' The time and its time zone.
DATETIMELTZ'...' DATETIME WITH LOCAL TIME ZONE '...' The time in UTC; it is shown in the session's time zone.
TIMESTAMPTZ'...' TIMESTAMP WITH TIME ZONE '...' The time and its time zone.
TIMESTAMPLTZ'...' TIMESTAMP WITH LOCAL TIME ZONE '...' The time in UTC; it is shown in the session's time zone.
DATETIMETZ'2025-12-31 14:30:05 +02:00'
DATETIMETZ'2025-12-31 14:30:05 Europe/Bucharest'
TIMESTAMPTZ'12/31/2025 02:30:05 PM Europe/Bucharest'
DATETIME WITH LOCAL TIME ZONE '2025-12-31 14:30:05 +02:00'

For how the time zone types behave, see Date/time types with timezone.

A bit string can be written in binary or in hexadecimal:

  • Binary: B'...' with the digits 0 and 1 in quotes, or 0b followed by the digits.
  • Hexadecimal: X'...' with hexadecimal digits in quotes, or 0x followed by the digits.

Binary values are padded with zeros on the right to a multiple of 8 bits, and hexadecimal values to a multiple of 2 digits. All the comparisons below are true:

SELECT B'10100000' = X'a0', 0b10100000 = 0xA0, B'1' = X'80', X'a' = X'a0' FROM db_root;
B'10100000'=X'a0' B'10100000'=X'A0' B'1'=X'80' X'a'=X'a0'
1 1 1 1

Enclose a character string in single quotes. To include a single quote, write it twice:

SELECT 'It''s shipped' FROM db_root;
'It''s shipped'
It's shipped

A backslash is an ordinary character by default, so 'C:\temp' is stored as written. Backslash escape sequences such as \n are available only when the no_backslash_escapes parameter is set to no; see Escape special characters.

Double quotes enclose identifiers, not strings (see Identifiers).

A character set introducer can precede a string and a COLLATE clause can follow it, for example _utf8'Blaye' COLLATE utf8_en_ci. See Charset introducer.

Values of the collection types SET, MULTISET and LIST (also called SEQUENCE) are written as elements in braces:

{'c', 'c', 'b', 'a'}

A brace literal on its own is a LIST (SEQUENCE), which keeps duplicates and order. Stored in a SET column, {'c', 'c', 'b', 'a'} becomes {'a', 'b', 'c'}: duplicates are removed and the elements sorted. See Collection types.

NULL (or null) means that there is no value. It is neither 0 nor the empty string ''. Comparing anything with NULL using = gives NULL, not true or false; use IS NULL instead:

SELECT NULL IS NULL, NULL = 0, '' IS NULL FROM db_root;
null is null null=0 '' is null
1 NULL 0