sqlglot.dialects.redshift
1from __future__ import annotations 2 3from sqlglot.typing.redshift import EXPRESSION_METADATA 4from sqlglot.dialects.dialect import NormalizationStrategy 5from sqlglot.dialects.postgres import Postgres 6from sqlglot.generators.redshift import RedshiftGenerator 7from sqlglot.parsers.redshift import RedshiftParser 8from sqlglot.tokens import TokenType 9 10 11class Redshift(Postgres): 12 # https://docs.aws.amazon.com/redshift/latest/dg/r_names.html 13 NORMALIZATION_STRATEGY = NormalizationStrategy.CASE_INSENSITIVE 14 15 NORMALIZE_NOT_NULL = True 16 17 EXPRESSION_METADATA = EXPRESSION_METADATA.copy() 18 SUPPORTS_USER_DEFINED_TYPES = False 19 INDEX_OFFSET = 0 20 COPY_PARAMS_ARE_CSV = False 21 HEX_LOWERCASE = True 22 HAS_DISTINCT_ARRAY_CONSTRUCTORS = True 23 COALESCE_COMPARISON_NON_STANDARD = True 24 REGEXP_EXTRACT_POSITION_OVERFLOW_RETURNS_NULL = False 25 ARRAY_FUNCS_PROPAGATES_NULLS = True 26 ARRAY_REMOVE_PROPAGATES_NULLS = True 27 28 # ref: https://docs.aws.amazon.com/redshift/latest/dg/r_FORMAT_strings.html 29 TIME_FORMAT = "'YYYY-MM-DD HH24:MI:SS'" 30 31 TIME_MAPPING = { 32 **Postgres.TIME_MAPPING, 33 "MON": "%b", 34 "MONTH": "%B", 35 } 36 37 Parser = RedshiftParser 38 39 UNESCAPED_SEQUENCES = {"\\a": "a", "\\v": "v"} 40 41 class Tokenizer(Postgres.Tokenizer): 42 NUMERIC_ESCAPES = {"0": (8, 1, 3, 0o777)} 43 NUMERIC_ESCAPES_ARE_BYTES = True 44 DROP_UNKNOWN_ESCAPES = True 45 BIT_STRINGS = [] 46 HEX_STRINGS = [] 47 UNICODE_IDENTIFIERS = [] 48 STRING_ESCAPES = ["\\", "'"] 49 50 KEYWORDS = { 51 **Postgres.Tokenizer.KEYWORDS, 52 "(+)": TokenType.JOIN_MARKER, 53 "BINARY VARYING": TokenType.VARBINARY, 54 "CURRENT_USER_ID": TokenType.CURRENT_USER_ID, 55 "HLLSKETCH": TokenType.HLLSKETCH, 56 "MINUS": TokenType.EXCEPT, 57 "SUPER": TokenType.SUPER, 58 "TOP": TokenType.TOP, 59 "UNLOAD": TokenType.COMMAND, 60 "USER": TokenType.CURRENT_USER, 61 "VARBYTE": TokenType.VARBINARY, 62 } 63 KEYWORDS.pop("VALUES") 64 65 # Redshift allows # to appear as a table identifier prefix 66 SINGLE_TOKENS = Postgres.Tokenizer.SINGLE_TOKENS.copy() 67 SINGLE_TOKENS.pop("#") 68 69 Generator = RedshiftGenerator
12class Redshift(Postgres): 13 # https://docs.aws.amazon.com/redshift/latest/dg/r_names.html 14 NORMALIZATION_STRATEGY = NormalizationStrategy.CASE_INSENSITIVE 15 16 NORMALIZE_NOT_NULL = True 17 18 EXPRESSION_METADATA = EXPRESSION_METADATA.copy() 19 SUPPORTS_USER_DEFINED_TYPES = False 20 INDEX_OFFSET = 0 21 COPY_PARAMS_ARE_CSV = False 22 HEX_LOWERCASE = True 23 HAS_DISTINCT_ARRAY_CONSTRUCTORS = True 24 COALESCE_COMPARISON_NON_STANDARD = True 25 REGEXP_EXTRACT_POSITION_OVERFLOW_RETURNS_NULL = False 26 ARRAY_FUNCS_PROPAGATES_NULLS = True 27 ARRAY_REMOVE_PROPAGATES_NULLS = True 28 29 # ref: https://docs.aws.amazon.com/redshift/latest/dg/r_FORMAT_strings.html 30 TIME_FORMAT = "'YYYY-MM-DD HH24:MI:SS'" 31 32 TIME_MAPPING = { 33 **Postgres.TIME_MAPPING, 34 "MON": "%b", 35 "MONTH": "%B", 36 } 37 38 Parser = RedshiftParser 39 40 UNESCAPED_SEQUENCES = {"\\a": "a", "\\v": "v"} 41 42 class Tokenizer(Postgres.Tokenizer): 43 NUMERIC_ESCAPES = {"0": (8, 1, 3, 0o777)} 44 NUMERIC_ESCAPES_ARE_BYTES = True 45 DROP_UNKNOWN_ESCAPES = True 46 BIT_STRINGS = [] 47 HEX_STRINGS = [] 48 UNICODE_IDENTIFIERS = [] 49 STRING_ESCAPES = ["\\", "'"] 50 51 KEYWORDS = { 52 **Postgres.Tokenizer.KEYWORDS, 53 "(+)": TokenType.JOIN_MARKER, 54 "BINARY VARYING": TokenType.VARBINARY, 55 "CURRENT_USER_ID": TokenType.CURRENT_USER_ID, 56 "HLLSKETCH": TokenType.HLLSKETCH, 57 "MINUS": TokenType.EXCEPT, 58 "SUPER": TokenType.SUPER, 59 "TOP": TokenType.TOP, 60 "UNLOAD": TokenType.COMMAND, 61 "USER": TokenType.CURRENT_USER, 62 "VARBYTE": TokenType.VARBINARY, 63 } 64 KEYWORDS.pop("VALUES") 65 66 # Redshift allows # to appear as a table identifier prefix 67 SINGLE_TOKENS = Postgres.Tokenizer.SINGLE_TOKENS.copy() 68 SINGLE_TOKENS.pop("#") 69 70 Generator = RedshiftGenerator
Specifies the strategy according to which identifiers should be normalized.
Whether the ARRAY constructor is context-sensitive, i.e in Redshift ARRAY[1, 2, 3] != ARRAY(1, 2, 3) as the former is of type INT[] vs the latter which is SUPER
Whether COALESCE in comparisons has non-standard NULL semantics.
We can't convert COALESCE(x, 1) = 2 into NOT x IS NULL AND x = 2 for redshift,
because they are not always equivalent. For example, if x is NULL and it comes
from a table, then the result is NULL, despite FALSE AND NULL evaluating to FALSE.
In standard SQL and most dialects, these expressions are equivalent, but Redshift treats table NULLs differently in this context.
Whether REGEXP_EXTRACT returns NULL when the position arg exceeds the string length.
Whether Array update functions return NULL when the input array is NULL.
Whether ARRAY_REMOVE returns NULL when the removal value is NULL.
Associates this dialect's time formats with their equivalent Python strftime formats.
Mapping of an escaped sequence (\n) to its unescaped version (
).
Whether string literals support escape sequences (e.g. \n). Set by the metaclass based on the tokenizer's STRING_ESCAPES.
Whether byte string literals support escape sequences. Set by the metaclass based on the tokenizer's BYTE_STRING_ESCAPES.
Mapping of an identifier escape char (\) to its escaped version (\\). Set by the metaclass based on the tokenizer's IDENTIFIER_ESCAPES.
Inherited Members
- sqlglot.dialects.postgres.Postgres
- ASCII_ONLY_NORMALIZATION
- TYPED_DIVISION
- CONCAT_COALESCE
- CONCAT_WS_COALESCE
- NULL_ORDERING
- SUPPORTS_LIMIT_ALL
- COLUMN_ALIAS_PRECEDENCE
- TABLESAMPLE_SIZE_IS_PERCENT
- TABLES_REFERENCEABLE_AS_COLUMNS
- OUTER_COLUMNS_SHADOW_TABLE_ALIASES
- EXTRACT_DATE_PART_MAPPING
- DEFAULT_FUNCTIONS_COLUMN_NAMES
42 class Tokenizer(Postgres.Tokenizer): 43 NUMERIC_ESCAPES = {"0": (8, 1, 3, 0o777)} 44 NUMERIC_ESCAPES_ARE_BYTES = True 45 DROP_UNKNOWN_ESCAPES = True 46 BIT_STRINGS = [] 47 HEX_STRINGS = [] 48 UNICODE_IDENTIFIERS = [] 49 STRING_ESCAPES = ["\\", "'"] 50 51 KEYWORDS = { 52 **Postgres.Tokenizer.KEYWORDS, 53 "(+)": TokenType.JOIN_MARKER, 54 "BINARY VARYING": TokenType.VARBINARY, 55 "CURRENT_USER_ID": TokenType.CURRENT_USER_ID, 56 "HLLSKETCH": TokenType.HLLSKETCH, 57 "MINUS": TokenType.EXCEPT, 58 "SUPER": TokenType.SUPER, 59 "TOP": TokenType.TOP, 60 "UNLOAD": TokenType.COMMAND, 61 "USER": TokenType.CURRENT_USER, 62 "VARBYTE": TokenType.VARBINARY, 63 } 64 KEYWORDS.pop("VALUES") 65 66 # Redshift allows # to appear as a table identifier prefix 67 SINGLE_TOKENS = Postgres.Tokenizer.SINGLE_TOKENS.copy() 68 SINGLE_TOKENS.pop("#")
Inherited Members
- sqlglot.tokens.Tokenizer
- Tokenizer
- NATIONAL_RAW_STRINGS
- RAW_STRINGS
- IDENTIFIERS
- QUOTES
- IDENTIFIER_ESCAPES
- STRING_ESCAPES_ALLOWED_IN_RAW_STRINGS
- LONE_SURROGATE_REPLACEMENT
- NESTED_COMMENTS
- DASH_COMMENT_REQUIRES_BOUNDARY
- COMMENTS_TERMINATE_AT_NEWLINE_ONLY
- UNQUOTED_PATH_TERMINATORS
- HINT_START
- TOKENS_PRECEDING_HINT
- COMMAND_PREFIX_TOKENS
- NUMERIC_LITERALS
- NUMBERS_CAN_HAVE_DECIMALS
- COMMENTS
- dialect
- tokenize
- sql
- size
- tokens