SnowConvert AI - Redshift - Expressions¶
Expression lists¶
Description¶
An expression list is a combination of expressions, and can appear in membership and comparison conditions (WHERE clauses) and in GROUP BY clauses. (Redshift SQL Language Reference Expression lists).
Note
This syntax is fully supported in Snowflake.
Grammar Syntax¶
Sample Source Patterns¶
Setup data¶
Redshift¶
IN Clause¶
Input Code:¶
Redshift¶
Result¶
ID |
NAME |
QUANTITY |
FRUIT |
PRICE |
|---|---|---|---|---|
1 |
Alice |
1 |
apple |
100 |
2 |
Bob |
5 |
banana |
200 |
3 |
Charlie |
10 |
cherry |
300 |
Output Code:¶
Snowflake¶
Result¶
ID |
NAME |
QUANTITY |
FRUIT |
PRICE |
|---|---|---|---|---|
1 |
Alice |
1 |
apple |
100 |
2 |
Bob |
5 |
banana |
200 |
3 |
Charlie |
10 |
cherry |
300 |
Comparisons¶
Input Code:¶
Redshift¶
Result¶
ID |
NAME |
QUANTITY |
FRUIT |
PRICE |
|---|---|---|---|---|
1 |
Alice |
1 |
apple |
100 |
Output Code:¶
Snowflake¶
Result¶
ID |
NAME |
QUANTITY |
FRUIT |
PRICE |
|---|---|---|---|---|
1 |
Alice |
1 |
apple |
100 |
Note
Expression list comparisons with the following operators may have a different behavior in Snowflake. ( < , <= , > , >=). These operators are transformed into logical AND operations to achieve full equivalence in Snowflake.
Input Code:¶
Redshift¶
Result¶
R1 |
R2 |
R3 |
R4 |
R5 |
|---|---|---|---|---|
FALSE |
FALSE |
NULL |
NULL |
FALSE |
Output Code:¶
Snowflake¶
Result¶
R1 |
R2 |
R3 |
R4 |
R5 |
|---|---|---|---|---|
FALSE |
FALSE |
NULL |
NULL |
FALSE |
Nested tuples¶
Input Code:¶
Redshift¶
Result¶
ID |
NAME |
QUANTITY |
FRUIT |
PRICE |
|---|---|---|---|---|
1 |
Alice |
1 |
apple |
100 |
2 |
Bob |
5 |
banana |
200 |
3 |
Charlie |
10 |
cherry |
300 |
Output Code¶
Snowflake¶
Result¶
ID |
NAME |
QUANTITY |
FRUIT |
PRICE |
|---|---|---|---|---|
1 |
Alice |
1 |
apple |
100 |
2 |
Bob |
5 |
banana |
200 |
3 |
Charlie |
10 |
cherry |
300 |
Case statement¶
Input Code:¶
Redshift¶
Result¶
RESULT |
|---|
Found |
Found |
Found |
Not Found |
Not Found |
Not Found |
Output Code¶
Snowflake¶
Result¶
RESULT |
|---|
Found |
Found |
Found |
Not Found |
Not Found |
Not Found |
Multiple Expressions¶
Input Code:¶
Redshift¶
Result¶
ID |
NAME |
QUANTITY |
FRUIT |
PRICE |
|---|---|---|---|---|
1 |
Alice |
1 |
apple |
100 |
2 |
Bob |
5 |
banana |
200 |
3 |
Charlie |
10 |
cherry |
300 |
Output Code¶
Snowflake¶
Result¶
ID |
NAME |
QUANTITY |
FRUIT |
PRICE |
|---|---|---|---|---|
1 |
Alice |
1 |
apple |
100 |
2 |
Bob |
5 |
banana |
200 |
3 |
Charlie |
10 |
cherry |
300 |
Joins¶
Input Code:¶
Redshift¶
Result¶
QUANTITY |
FRUIT |
QUANTITY |
FRUIT |
|---|---|---|---|
one |
apple |
one |
apple |
Output Code¶
Snowflake¶
Result¶
QUANTITY |
FRUIT |
QUANTITY |
FRUIT |
|---|---|---|---|
one |
apple |
one |
apple |
Known Issues ¶
No issues were found.
Compound Expressions¶
Description ¶
A compound expression is a series of simple expressions joined by arithmetic operators. A simple expression used in a compound expression must return a numeric value.
Grammar Syntax ¶
Conversion Table¶
| Redshift | Snowflake | Comments |
|---|---|---|
|| (Concatenation) | || | Fully supported by Snowflake |
Sample Source Patterns¶
Input Code:¶
Redshift¶
Results¶
concat_string_number |
|---|
Hello has number 42 |
<NULL> |
Redshift has number -7 |
concat_string_date |
|---|
Hello on 2023-12-01 |
<NULL> |
<NULL> |
concat_with_null_handling |
|---|
Hello with number 42 |
Unknown with number 0 |
Redshift with number -7 |
Output Code:
Snowflake¶
Results¶
concat_string_number |
|---|
Hello has number 42 |
<NULL> |
Redshift has number -7 |
concat_string_date |
|---|
Hello on 2023-12-01 |
<NULL> |
<NULL> |
concat_with_null_handling |
|---|
Hello with number 42 |
Unknown with number 0 |
Redshift with number -7 |
Known Issues¶
No issues were found.
Related EWIs¶
There are no known issues.
Arithmetic operators¶
Operators
Translation for Arithmetic Operators
Conversion Table¶
| Redshift | Snowflake | Comments |
|---|---|---|
| +/- (positive and negative sign/operator) | +/- | Fully supported by Snowflake |
| ^ (exponentiation) | POWER | Fully supported by Snowflake |
| * (multiplication) | * | Fully supported by Snowflake |
| / (division) | / | Redshift division between integers always returns integer value, FLOOR function is added to emulate this behavior. |
| % (modulo) | % | Fully supported by Snowflake |
| + (addition) | + and || | Fully supported by Snowflake. When string are added, it is transformed to a concat. |
| - (subtraction) | - | Fully supported by Snowflake |
| @ (absolute value) | ABS | Fully supported by Snowflake |
| |/ (square root) | SQRT | Fully supported by Snowflake |
| ||/ (cube root) | CBRT | Fully supported by Snowflake |
Sample Source Patterns¶
Addition, Subtraction, Positive & Negative¶
Input Code:
Input Code:¶
Redshift¶
Results¶
| positive_value | negative_value | add_sub_result | next_day | one_hour_before | string_sum | int_string_sum | string_int_sum |
|---|---|---|---|---|---|---|---|
| 100.50 | -100.50 | 97.50 | 2024-12-02 10:30:00.000000 | 2024-12-01 09:30:00.000000 | Basic testType A | 105.5 | 105.5 |
| 250.75 | -250.75 | 243.75 | 2024-12-03 15:45:00.000000 | 2024-12-02 14:45:00.000000 | Complex operationsType B | 255.75 | 255.75 |
| -50.25 | 50.25 | -53.25 | 2024-12-04 20:00:00.000000 | 2024-12-03 19:00:00.000000 | Negative base valueType C | -45.25 | -45.25 |
| 0.00 | 0.00 | 8.00 | 2024-12-05 09:15:00.000000 | 2024-12-04 08:15:00.000000 | Zero base valueType D | 5 | 5 |
Output Code:
Snowflake¶
Results¶
| positive_value | negative_value | add_sub_result | next_day | one_hour_before | string_sum | int_string_sum | string_int_sum |
|---|---|---|---|---|---|---|---|
| 100.5 | -100.5 | 97.5 | 2024-12-02 10:30:00 | 2024-12-01 09:30:00 | Basic testType A | 105.5 | 105.5 |
| 250.75 | -250.75 | 243.75 | 2024-12-03 15:45:00 | 2024-12-02 14:45:00 | Complex operationsType B | 255.75 | 255.75 |
| -50.25 | 50.25 | -53.25 | 2024-12-04 20:00:00 | 2024-12-03 19:00:00 | Negative base valueType C | -45.25 | -45.25 |
| 0 | 0 | 8 | 2024-12-05 09:15:00 | 2024-12-04 08:15:00 | Zero base valueType D | 5 | 5 |
Exponentiation, multiplication, division & modulo¶
Input Code:¶
Redshift¶
Results¶
| raised_to_exponent | multiplied_value | divided_value | int_division | modulo_result | add_sub_result | controlled_eval |
|---|---|---|---|---|---|---|
| 10100.25 | 201 | 20.1 | 20 | 1 | 97.5 | 104.5 |
| 15766047.296875 | 752.25 | 25.075 | 25 | 1 | 243.75 | 259.75 |
| 6375940.62890625 | -251.25 | -6.28125 | -6 | 0 | -53.25 | -30.25 |
| 0 | 0 | 0 | 0 | 1 | 8 | 10 |
Output Code:¶
Snowflake¶
Results¶
| raised_to_exponent | multiplied_value | divided_value | int_division | modulo_result | add_sub_result | controlled_eval |
|---|---|---|---|---|---|---|
| 10100.25 | 201 | 20.1 | 20 | 1 | 97.5 | 104.5 |
| 15766047.2969 | 752.25 | 25.075 | 25 | 1 | 243.75 | 259.75 |
| 6375940.6289 | -251.25 | -6.2812 | -7 | 0 | -53.25 | -30.25 |
| 0 | 0 | 0 | 0 | 1 | 8 | 10 |
Absolute value, Square root and Cube root¶
Input Code:¶
Redshift¶
Results¶
Output Code:¶
Snowflake¶
Results¶
Known Issues¶
In Snowflake, it is possible to use the unary operators
+and-with string values, however in Redshift it is not valid.
Related EWIs¶
No related EWIs.
Bitwise operators¶
Operators
Translation for Bitwise Operators
Conversion Table¶
| Redshift | Snowflake | Comments |
|---|---|---|
& (AND) | BITAND | Fully supported by Snowflake |
| (OR) | BITOR | Fully supported by Snowflake |
<< (Shift Left) | BITSHIFTLEFT | |
>> (Shift Right) | BITSHIFTRIGHT | |
# (XOR) | BITXOR | Fully supported by Snowflake |
~ (NOT) | BITNOT | Fully supported by Snowflake |
Sample Source Patterns¶
Setup data¶
Redshift¶
Query¶
Snowflake¶
Query¶
Bitwise operators on integer values¶
Input Code:¶
Redshift¶
Results¶
Output Code:
Snowflake¶
Results¶
Bitwise operators on binary data¶
For the BITAND, BITOR and BITXOR functions the'LEFT' parameter is added to insert padding in case both binary values have different length, this is done to avoid errors when comparing the values in Snowflake.
Redshift¶
Query¶
Result¶
Snowflake¶
Query¶
Result¶
Known Issues¶
No issues were found.
Related EWIs¶
SSC-FDM-PG0010: Results may vary due to the behavior of Snowflake’s bitwise function.