- Wrong results in
cast - Only hexadecimal, not binary nor octal
- Only in literals, not in
cast - Also with underscores (_) between the digits
The SQL standard allows implementations to accept binary, octal and hexadecimal integers in statements.
SELECT 0b101010
, 0o52
, 0x2A
FROM …You need to prefix binary numbers with 0b, octal numbers with 0o and hexadecimal numbers with 0x. There must be no space between the prefix and the actual number. All letters are case insensitive: those in the prefix and those in hexadecimal numbers.
The literal syntax of SQL is also used when casting a character string to numeric types.0 Consequently, the examples are also valid in expressions such as cast('0x2a' as integer).
- Doesn’t fail, but returns the wrong result. E.g. just the “0“ before the first letter
Related
- Optional Features
Normative References
Integer literals with the radix (bases) 2, 8 and 16 is defined in ISO/IEC 9075-2:2023 as the optional feature T661, “Non-decimal integer literals”. It first appeared in the 2023 edition.

