SnowConvert AI - Redshift - Conditions¶
BETWEEN¶
Description¶
A
BETWEENcondition tests expressions for inclusion in a range of values, using the keywordsBETWEENandAND. (Redshift SQL Language Reference BETWEEN condition)
Grammar Syntax¶
Note
This function is fully supported by Snowflake.
Sample Source Patterns¶
Setup Table¶
Redshift¶
Snowflake¶
Input Code:¶
Redshift¶
Results¶
count |
|---|
8 |
id |
price |
departmentid |
saledate |
|---|---|---|---|
id |
price |
departmentid |
saledate |
|---|---|---|---|
1 |
5000 |
1 |
2008-01-01 |
2 |
8000 |
1 |
2018-01-01 |
3 |
5000 |
2 |
2010-01-01 |
4 |
7000 |
3 |
2010-01-01 |
5 |
5000 |
1 |
2018-01-01 |
6 |
4000 |
4 |
2010-01-01 |
7 |
3000 |
4 |
2018-01-01 |
8 |
9000 |
5 |
2008-01-01 |
9 |
7000 |
5 |
2018-01-01 |
10 |
6000 |
5 |
2006-01-01 |
11 |
5000 |
5 |
2008-01-01 |
12 |
5000 |
4 |
2018-01-01 |
13 |
8000 |
3 |
2006-01-01 |
14 |
7000 |
3 |
2016-01-01 |
15 |
2000 |
2 |
2018-01-01 |
id |
price |
departmentid |
saledate |
|---|---|---|---|
3 |
5000 |
2 |
2010-01-01 |
4 |
7000 |
3 |
2010-01-01 |
6 |
4000 |
4 |
2010-01-01 |
14 |
7000 |
3 |
2016-01-01 |
Output Code:¶
Snowflake¶
Results¶
count |
|---|
8 |
id |
price |
departmentid |
saledate |
|---|---|---|---|
id |
price |
departmentid |
saledate |
|---|---|---|---|
1 |
5000 |
1 |
2008-01-01 |
2 |
8000 |
1 |
2018-01-01 |
3 |
5000 |
2 |
2010-01-01 |
4 |
7000 |
3 |
2010-01-01 |
5 |
5000 |
1 |
2018-01-01 |
6 |
4000 |
4 |
2010-01-01 |
7 |
3000 |
4 |
2018-01-01 |
8 |
9000 |
5 |
2008-01-01 |
9 |
7000 |
5 |
2018-01-01 |
10 |
6000 |
5 |
2006-01-01 |
11 |
5000 |
5 |
2008-01-01 |
12 |
5000 |
4 |
2018-01-01 |
13 |
8000 |
3 |
2006-01-01 |
14 |
7000 |
3 |
2016-01-01 |
15 |
2000 |
2 |
2018-01-01 |
id |
price |
departmentid |
saledate |
|---|---|---|---|
3 |
5000 |
2 |
2010-01-01 |
4 |
7000 |
3 |
2010-01-01 |
6 |
4000 |
4 |
2010-01-01 |
14 |
7000 |
3 |
2016-01-01 |
Known Issues ¶
No issues were found.
Comparison Condition¶
Conditions
Description ¶
Comparison conditions state logical relationships between two values. All comparison conditions are binary operators with a Boolean return type.
Grammar Syntax ¶
Redshift supports the comparison operators described in the following table:
| Operator | Syntax | Description |
|---|---|---|
| < | a < b | Value a is less than value b. |
| > | a > b | Value a is greater than value b. |
| <= | a <= b | Value a is less than or equal to value b. |
| >= | a >= b | Value a is greater than or equal to value b. |
| = | a = b | Value a is equal to value b. |
| <> | != | a <> b | a != b | Value a is not equal to value b. |
| ANY | SOME | a = ANY(subquery) | Value a is equal to any value returned by the subquery. |
| ALL | a <> ALL or != ALL (subquery) | Value a is not equal to any value returned by the subquery. |
| IS TRUE | FALSE | UNKNOWN | a IS TRUE | Value a is Boolean TRUE. |
Use of comparison operators on Strings¶
It is important to note that in Redshift, comparison operators on strings ignore trailing blank spaces. To replicate this behavior in Snowflake, the transformation applies the RTRIM function to remove trailing spaces, ensuring equivalent functionality. For more information: Significance of trailing blanks
Conversion Table¶
Most of the operators are directly supported by Snowflake; however, the following operators require transformation:
| Redshift | Snowflake | Comments |
|---|---|---|
| (expression) IS TRUE | expression | Condition is TRUE. |
| (expression) IS FALSE | NOT (expression) | Condition is FALSE. |
| (expression) IS UNKNOWN | expression IS NULL | Expression evaluates to NULL (same as UNKNOWN). |
Sample Source Patterns¶
Input Code:¶
Redshift¶
Results¶
id |
value |
status |
category |
|---|---|---|---|
1 |
50 |
true |
A |
id |
value |
status |
category |
|---|---|---|---|
1 |
50 |
true |
A |
3 |
40 |
null |
C |
5 |
60 |
false |
B |
id |
value |
status |
category |
|---|---|---|---|
1 |
50 |
true |
A |
4 |
70 |
true |
A |
id |
value |
status |
category |
|---|---|---|---|
3 |
40 |
null |
C |
id |
value |
status |
category |
|---|---|---|---|
1 |
50 |
true |
A |
4 |
70 |
true |
A |
id |
value |
status |
category |
|---|---|---|---|
2 |
30 |
false |
B |
4 |
40 |
null |
C |
5 |
60 |
false |
B |
id |
value |
status |
category |
|---|---|---|---|
1 |
50 |
true |
A |
4 |
70 |
true |
A |
id |
value |
status |
category |
|---|---|---|---|
2 |
30 |
false |
B |
5 |
60 |
false |
B |
id |
value |
status |
category |
|---|---|---|---|
4 |
40 |
null |
C |
Output Code:
Snowflake¶
Results¶
id |
value |
status |
category |
|---|---|---|---|
1 |
50 |
true |
A |
id |
value |
status |
category |
|---|---|---|---|
1 |
50 |
true |
A |
3 |
40 |
null |
C |
5 |
60 |
false |
B |
id |
value |
status |
category |
|---|---|---|---|
1 |
50 |
true |
A |
4 |
70 |
true |
A |
id |
value |
status |
category |
|---|---|---|---|
3 |
40 |
null |
C |
id |
value |
status |
category |
|---|---|---|---|
1 |
50 |
true |
A |
4 |
70 |
true |
A |
id |
value |
status |
category |
|---|---|---|---|
2 |
30 |
false |
B |
4 |
40 |
null |
C |
5 |
60 |
false |
B |
id |
value |
status |
category |
|---|---|---|---|
1 |
50 |
true |
A |
4 |
70 |
true |
A |
id |
value |
status |
category |
|---|---|---|---|
2 |
30 |
false |
B |
5 |
60 |
false |
B |
id |
value |
status |
category |
|---|---|---|---|
4 |
40 |
null |
C |
Known Issues¶
No issues were found.
Related EWIs¶
There are no known issues.
EXISTS¶
Description¶
EXISTS conditions test for the existence of rows in a subquery, and return true if a subquery returns at least one row. If NOT is specified, the condition returns true if a subquery returns no rows. (Redshift SQL Language Reference EXISTS condition)
Grammar Syntax¶
Note
This function is fully supported by Snowflake.
Sample Source Patterns¶
Setup Table¶
Input Code:¶
Redshift¶
Results¶
ID |
NAME |
LASTNAME |
|---|---|---|
1 |
name1 |
lastname1 |
2 |
name2 |
NULL |
3 |
name3 |
lastname3 |
4 |
name4 |
NULL |
Output Code:¶
Snowflake¶
Results¶
ID |
NAME |
LASTNAME |
|---|---|---|
1 |
name1 |
lastname1 |
2 |
name2 |
NULL |
3 |
name3 |
lastname3 |
4 |
name4 |
NULL |
Related EWIs¶
No related EWIs.
Known Issues ¶
No issues were found.
IN¶
Description¶
An IN condition tests a value for membership in a set of values or in a subquery. (Redshift SQL Language Reference IN condition)
Grammar Syntax¶
Note
This function is fully supported by Snowflake.
Sample Source Patterns¶
Setup Table¶
Redshift¶
Snowflake¶
Input Code:¶
Redshift¶
Results¶
ID |
PRICE |
SALEDATE |
|---|---|---|
2 |
4000 |
2024-12-18 |
3 |
2000 |
2024-12-17 |
VALIDID |
|---|
TRUE |
R1 |
R2 |
|---|---|
TRUE |
FALSE |
TRUE |
TRUE |
Output Code:¶
Snowflake¶
Results¶
ID |
PRICE |
SALEDATE |
|---|---|---|
2 |
4000 |
2024-12-18 |
3 |
2000 |
2024-12-17 |
VALIDID |
|---|
TRUE |
R1 |
R2 |
|---|---|
TRUE |
FALSE |
TRUE |
TRUE |
Related EWIs¶
No related EWIs.
Known Issues ¶
No issues were found.
Logical Conditions¶
Description ¶
Logical conditions combine the result of two conditions to produce a single result. All logical conditions are binary operators with a Boolean return type. (Redshift SQL Language reference Logical Conditions).
Note
This grammar is fully supported in Snowflake.
Grammar Syntax ¶
E1 |
E2 |
E1 AND E2 |
E1 OR E2 |
NOT E2 |
|---|---|---|---|---|
TRUE |
TRUE |
TRUE |
TRUE |
FALSE |
TRUE |
FALSE |
FALSE |
TRUE |
TRUE |
TRUE |
UNKNOWN |
UNKNOWN |
TRUE |
UNKNOWN |
FALSE |
TRUE |
FALSE |
TRUE |
|
FALSE |
FALSE |
FALSE |
FALSE |
|
FALSE |
UNKNOWN |
FALSE |
UNKNOWN |
|
UNKNOWN |
TRUE |
UNKNOWN |
TRUE |
|
UNKNOWN |
FALSE |
FALSE |
UNKNOWN |
|
UNKNOWN |
UNKNOWN |
UNKNOWN |
UNKNOWN |
Sample Source Patterns¶
Setup data¶
Redshift¶
Input Code:¶
Redshift¶
Results¶
| EMPLOYEE_ID | IS_ACTIVE_ENGINEERING | HR_OR_HIGH_SALARY | IS_INACTIVE | HIRE_DATE_MISSING | LOW_SALARY_OR_NO_SALARY |
|---|---|---|---|---|---|
| 1 | TRUE | TRUE | FALSE | FALSE | FALSE |
| 2 | FALSE | TRUE | TRUE | FALSE | FALSE |
| 3 | FALSE | FALSE | NULL | FALSE | FALSE |
| 4 | TRUE | TRUE | FALSE | TRUE | FALSE |
| 5 | FALSE | NULL | FALSE | FALSE | TRUE |
Output Code:
Snowflake¶
Results¶
| EMPLOYEE_ID | IS_ACTIVE_ENGINEERING | HR_OR_HIGH_SALARY | IS_INACTIVE | HIRE_DATE_MISSING | LOW_SALARY_OR_NO_SALARY |
|---|---|---|---|---|---|
| 1 | TRUE | TRUE | FALSE | FALSE | FALSE |
| 2 | FALSE | TRUE | TRUE | FALSE | FALSE |
| 3 | FALSE | FALSE | NULL | FALSE | FALSE |
| 4 | TRUE | TRUE | FALSE | TRUE | FALSE |
| 5 | FALSE | NULL | FALSE | FALSE | TRUE |
Known Issues¶
No issues were found.
Related EWIs¶
There are no known issues.
NULL¶
Description¶
The null condition tests for nulls, when a value is missing or unknown. (Redshift SQL Language Reference NULL condition)
Grammar Syntax¶
Note
This function is fully supported by Snowflake.
Sample Source Patterns¶
Setup Table¶
Redshift¶
Snowflake¶
Input Code:¶
Redshift¶
Results¶
ID |
NAME |
LASTNAME |
|---|---|---|
2 |
name2 |
NULL |
4 |
name4 |
NULL |
Output Code:¶
Snowflake¶
Results¶
ID |
NAME |
LASTNAME |
|---|---|---|
2 |
name2 |
NULL |
4 |
name4 |
NULL |
Known Issues ¶
No issues were found.
Related EWIs¶
No related EWIs.
Pattern-matching conditions¶
Description ¶
A pattern-matching operator searches a string for a pattern specified in the conditional expression and returns true or false depend on whether it finds a match. Amazon Redshift uses three methods for pattern matching:
LIKE expressions The LIKE operator compares a string expression, such as a column name, with a pattern that uses the wildcard characters
%(percent) and_(underscore). LIKE pattern matching always covers the entire string. LIKE performs a case-sensitive match and ILIKE performs a case-insensitive match.SIMILAR TO regular expressions The SIMILAR TO operator matches a string expression with a SQL standard regular expression pattern, which can include a set of pattern-matching metacharacters that includes the two supported by the LIKE operator. SIMILAR TO matches the entire string and performs a case-sensitive match.
POSIX-style regular expressions POSIX regular expressions provide a more powerful means for pattern matching than the LIKE and SIMILAR TO operators. POSIX regular expression patterns can match any portion of the string and performs a case-sensitive match. (Redshift SQL Language reference Pattern-matching conditions).
Known Issues¶
In Snowflake, the behavior for scenarios such as (
LIKE,SIMILARTO, andPOSIX Operators) can vary when the column is of type CHAR. For example:
Code¶
Redshift Results¶
like(CHAR(10)) |
like(VARCHAR(10)) |
|---|---|
FALSE |
TRUE |
TRUE |
TRUE |
FALSE |
TRUE |
Snowflake Results¶
like(CHAR(10)) |
like(VARCHAR(10)) |
|---|---|
TRUE |
TRUE |
TRUE |
TRUE |
TRUE |
TRUE |
It appears that, because CHAR(10) is “fixed-length,” it assumes the ‘%1’ pattern must match a ‘1’ in the 10th position of a CHAR(10) column. However, in Snowflake, it matches if a ‘1’ exists in the string, with any sequence of zero or more characters preceding it.
LIKE¶
Pattern-matching conditions
Description ¶
The LIKE operator compares a string expression, such as a column name, with a pattern that uses the wildcard characters % (percent) and _ (underscore). LIKE pattern matching always covers the entire string. To match a sequence anywhere within a string, the pattern must start and end with a percent sign. (Redshift SQL Language reference LIKE).
Note
This grammar is fully supported in Snowflake.
Note
In Snowflake the cases where the escape character is not provided, the default Redshift escape character '\\' will be added for full equivalence.
Grammar Syntax ¶
Sample Source Patterns¶
Setup data¶
Redshift¶
Like¶
Input Code:¶
Redshift¶
Results¶
NAME |
|---|
Joe Doe |
Joe Doe |
Joe Doe |
Joe Doe |
John Dddoe |
Output Code:
Snowflake¶
Results¶
NAME |
|---|
Joe Doe |
Joe Doe |
Joe Doe |
Joe Doe |
John Dddoe |
Not like¶
Input Code:¶
Redshift¶
Results¶
NAME |
|---|
100% |
1000 times |
Elaine |
Joe down |
John_down |
Output Code:
Snowflake¶
Results¶
NAME |
|---|
100% |
1000 times |
Elaine |
Joe down |
John_down |
Escape characters¶
Input Code:¶
Redshift¶
Results¶
NAME |
|---|
John_down |
NAME |
|---|
100% |
Output Code:
Snowflake¶
Results¶
NAME |
|---|
John_down |
NAME |
|---|
100% |
ILike¶
Input Code:¶
Redshift¶
Results¶
R1 |
R2 |
|---|---|
FALSE |
TRUE |
Output Code:
Snowflake¶
Results¶
R1 |
R2 |
|---|---|
FALSE |
TRUE |
Operators¶
The following operators are translated as follows:
Redshift |
Snowflake |
|---|---|
~~ |
LIKE |
!~~ |
NOT LIKE |
~~* |
ILIKE |
!~~* |
NOT ILIKE |
Input Code:¶
Redshift¶
Results¶
R1 |
R2 |
R3 |
R4 |
|---|---|---|---|
TRUE |
FALSE |
TRUE |
FALSE |
Output Code:
Snowflake¶
Results¶
R1 |
R2 |
R3 |
R4 |
|---|---|---|---|
TRUE |
FALSE |
TRUE |
FALSE |
Known Issues¶
The behavior of fixed char types may differ. See Known issues for more information.
Related EWIs¶
There are no known issues.
POSIX Operators¶
Pattern-matching conditions
Description ¶
A POSIX regular expression is a sequence of characters that specifies a match pattern. A string matches a regular expression if it is a member of the regular set described by the regular expression. POSIX regular expression patterns can match any portion of a string. (Redshift SQL Language reference POSIX Operators).
Warning
This grammar is partially supported in Snowflake. POSIX Operators are transformed to REGEXP_COUNT in Snowflake.
Grammar Syntax ¶
POSIX pattern-matching metacharacters¶
POSIX pattern matching supports the following metacharacters (all the cases are supported in Snowflake):
POSIX |
Description |
|---|---|
. |
Matches any single character. |
|
Matches zero or more occurrences. |
|
Matches one or more occurrences. |
|
Matches zero or one occurrence. |
|
Specifies alternative matches. |
|
Matches the beginning-of-line character. |
|
Matches the end-of-line character. |
|
Matches the end of the string. |
[ ] |
Brackets specify a matching list, that should match one expression in the list. |
|
Parentheses group items into a single logical item. |
|
Repeat the previous item exactly m times. |
|
Repeat the previous item m or more times. |
|
Repeat the previous item at least m and not more than n times. |
|
Matches any character within a POSIX character class. In the following character classes, Amazon Redshift supports only ASCII characters, just like Snowflake: |
The parameters ‘m’ (enables multiline mode) and ‘s’ (allows the POSIX wildcard character . to match new lines) are used to achieve full equivalence in Snowflake. For more information please refer to Specifying the parameters for the regular expression in Snowflake.
Sample Source Patterns¶
Setup data¶
Redshift¶
. : Matches any character¶
Input Code:¶
Redshift¶
Results¶
ID |
COLUMN_NAME |
|---|---|
1 |
abc123 hello world |
3 |
123abc another line abc123 |
11 |
abc123 abc456 abc789 |
Output Code:
Snowflake¶
Results¶
ID |
COLUMN_NAME |
|---|---|
1 |
abc123 hello world |
3 |
123abc another line abc123 |
11 |
abc123 abc456 abc789 |
* : Matches zero or more occurrences.¶
Input Code:¶
Redshift¶
Results¶
ID |
COLUMN_NAME |
|---|---|
1 |
abc123 hello world |
3 |
123abc another line abc123 |
6 |
a@b#c! more text here |
7 |
alpha beta gamma |
11 |
abc123 abc456 abc789 |
Output Code:
Snowflake¶
Results¶
ID |
COLUMN_NAME |
|---|---|
1 |
abc123 hello world |
3 |
123abc another line abc123 |
6 |
a@b#c! more text here |
7 |
alpha beta gamma |
11 |
abc123 abc456 abc789 |
? : Matches zero or one occurrence¶
Input Code:¶
Redshift¶
Results¶
ID |
COLUMN_NAME |
|---|---|
2 |
test string with multiple lines in this entry |
4 |
line1 line2 line3 |
5 |
start middle end |
8 |
uppercase lowercase |
9 |
line1 line2 line3 line4 |
10 |
1234567890 more digits |
12 |
start end middle |
13 |
this is the first line this is the second line |
14 |
special characters !@#$%^&*() |
Output Code:
Snowflake¶
Results¶
ID |
COLUMN_NAME |
|---|---|
2 |
test string with multiple lines in this entry |
4 |
line1 line2 line3 |
5 |
start middle end |
8 |
uppercase lowercase |
9 |
line1 line2 line3 line4 |
10 |
1234567890 more digits |
12 |
start end middle |
13 |
this is the first line this is the second line |
14 |
special characters !@#$%^&*() |
^ : Matches the beginning-of-line character¶
Input Code:¶
Redshift¶
Results¶
ID |
COLUMN_NAME |
|---|---|
1 |
abc123 hello world |
3 |
123abc another line abc123 |
11 |
abc123 abc456 abc789 |
Output Code:
Snowflake¶
Results¶
ID |
COLUMN_NAME |
|---|---|
1 |
abc123 hello world |
3 |
123abc another line abc123 |
11 |
abc123 abc456 abc789 |
$ : Matches the end of the string.¶
Input Code:¶
Redshift¶
Results¶
ID |
COLUMN_NAME |
|---|---|
2 |
test string with multiple lines in this entry |
4 |
line1 line2 line3 |
5 |
start middle end |
6 |
a@b#c! more text here |
7 |
alpha beta gamma |
8 |
uppercase lowercase |
9 |
line1 line2 line3 line4 |
10 |
1234567890 more digits |
12 |
start end middle |
13 |
this is the first line this is the second line |
14 |
special characters !@#$%^&*() |
Output Code:
Snowflake¶
Results¶
ID |
COLUMN_NAME |
|---|---|
2 |
test string with multiple lines in this entry |
4 |
line1 line2 line3 |
5 |
start middle end |
6 |
a@b#c! more text here |
7 |
alpha beta gamma |
8 |
uppercase lowercase |
9 |
line1 line2 line3 line4 |
10 |
1234567890 more digits |
12 |
start end middle |
13 |
this is the first line this is the second line |
14 |
special characters !@#$%^&*() |
Usage of collate columns¶
Arguments with COLLATE specifications are not currently supported in the RLIKE function. As a result, the COLLATE clause must be disabled to use this function. However, this may lead to differences in the results.
Input Code:¶
Redshift¶
Results¶
CI |
CS |
|---|---|
TRUE |
FALSE |
Output Code:
Snowflake¶
Results¶
CI |
CS |
|---|---|
FALSE |
FALSE |
If you require equivalence for these scenarios, you can manually add the following parameters to the function to achieve functional equivalence:
Parameter |
Description |
|---|---|
|
Case-sensitive matching |
|
Case-insensitive matching |
Known Issues¶
Known Issues¶
The behavior of fixed char types may differ. See Known issues for more information.
Arguments with COLLATE specifications are not currently supported in the REGEXP_COUNT function.
Related EWIs¶
SSC-FDM-PG0011: The use of the COLLATE column constraint has been disabled for this pattern-matching condition.
SIMILAR TO¶
Pattern-matching conditions
Description ¶
The SIMILAR TO operator matches a string expression, such as a column name, with a SQL standard regular expression pattern. A SQL regular expression pattern can include a set of pattern-matching metacharacters, including the two supported by the LIKE operator. (Redshift SQL Language reference SIMILAR TO).
Grammar Syntax ¶
Pattern-matching metacharacters¶
| Redshift | Snowflake | Notes |
|---|---|---|
| ```{code} sql :force: % ``` | ```{code} sql :force: .* ``` | Matches any sequence of zero or more characters. To achieve full equivalence in Snowflake, we need to replace the '%' operator with '.*' in the pattern. |
| ```{code} sql :force: _ ``` | ```{code} sql :force: . ``` | Matches any single character. To achieve full equivalence in Snowflake, we need to replace the _ operator with . and add the s parameter to enable the POSIX wildcard character . to match newline characters. |
| ```{code} sql :force: | ``` | ```{code} sql :force: | ``` | Denotes alternation. This case is fully supported in Snowflake. |
| ```{code} sql :force: * ``` | ```{code} sql :force: * ``` | Repeat the previous item zero or more times. This can have a different behavior when newline characters are included. |
| ```{code} sql :force: + ``` | ```{code} sql :force: + ``` | Repeat the previous item one or more times. This can have a different behavior when newline characters are included. |
| ```{code} sql :force: ? ``` | ```{code} sql :force: ? ``` | Repeat the previous item zero or one time. This can have a different behavior when newline characters are included. |
| ```{code} sql :force: {m} ``` | ```{code} sql :force: {m} ``` | Repeat the previous item exactly m times and it is fully supported in Snowflake. |
| ```{code} sql :force: {m,} ``` | ```{code} sql :force: {m,} ``` | Repeat the previous item at least m and not more than n times and it is fully supported in Snowflake. |
| ```{code} sql :force: {m,n} ``` | ```{code} sql :force: {m,n} ``` | Repeat the previous item m or more times and it is fully supported in Snowflake. |
| ```{code} sql :force: () ``` | ```{code} sql :force: () ``` | Parentheses group items into a single logical item and it is fully supported in Snowflake. |
| ```{code} sql :force: [...] ``` | ```{code} sql :force: [...] ``` | A bracket expression specifies a character class, just as in POSIX regular expressions. |
Sample Source Patterns¶
Setup data¶
Redshift¶
% : Matches any sequence of zero or more characters¶
Input Code:¶
Redshift¶
Results¶
COLUMN_NAME |
|---|
abc_123 |
abcc |
xyzabc |
abc cccc |
abc%def |
abc_xyz |
abc_1_xyz |
start%_abc |
abcs_123_xyz |
aabc123 |
Output Code:
Snowflake¶
Results¶
COLUMN_NAME |
|---|
abc_123 |
abcc |
xyzabc |
abc cccc |
abc%def |
abc_xyz |
abc_1_xyz |
start%_abc |
abcs_123_xyz |
aabc123 |
_ : Matches any single character¶
Input Code:¶
Redshift¶
Results¶
COLUMN_NAME |
|---|
abc_123 |
a_cdef |
abcc |
abc cccc |
abc%def |
abc_xyz |
abc_1_xyz |
abcs_123_xyz |
Output Code:
Snowflake¶
Results¶
COLUMN_NAME |
|---|
abc_123 |
a_cdef |
abcc |
abc cccc |
abc%def |
abc_xyz |
abc_1_xyz |
abcs_123_xyz |
| : Denotes alternation¶
Input Code:¶
Redshift¶
Results¶
COLUMN_NAME |
|---|
bxyz |
banana |
Output Code:
Snowflake¶
Results¶
COLUMN_NAME |
|---|
bxyz |
banana |
{m, n} : Repeat the previous item exactly m times.¶
Input Code:¶
Redshift¶
Results¶
COLUMN_NAME |
|---|
abcc |
Output Code:
Snowflake¶
Results¶
COLUMN_NAME |
|---|
abcc |
+ : Repeat the previous item one or more times¶
Input Code:¶
Redshift¶
Results¶
COLUMN_NAME |
|---|
abcc |
abc cccc |
Output Code:
Snowflake¶
Results¶
COLUMN_NAME |
|---|
abcc |
* : Repeat the previous item zero or more times¶
Input Code:¶
Redshift¶
Results¶
COLUMN_NAME |
|---|
abcc |
abc cccc |
Output Code:
Snowflake¶
Results¶
COLUMN_NAME |
|---|
abcc |
? : Repeat the previous item zero or one time¶
Input Code:¶
Redshift¶
Results¶
COLUMN_NAME |
|---|
abcc |
abc ccc |
Output Code:
Snowflake¶
Results¶
COLUMN_NAME |
|---|
abcc |
() : Parentheses group items into a single logical item¶
Input Code:¶
Redshift¶
Results¶
COLUMN_NAME |
|---|
abc_123 |
abcc |
xyzabc |
abc cccc |
abc%def |
abc_xyz |
abc_1_xyz |
abcs_123_xyz |
xyzxyz |
Output Code:
Snowflake¶
Results¶
COLUMN_NAME |
|---|
abc_123 |
abcc |
xyzabc |
abc cccc |
abc%def |
abc_xyz |
abc_1_xyz |
abcs_123_xyz |
xyzxyz |
[…] : Specifies a character class¶
Input Code:¶
Redshift¶
Results¶
COLUMN_NAME |
|---|
abc_123 |
a_cdef |
bxyz |
abcc |
apple |
banana |
abc cccc |
abc%def |
abc_xyz |
abc_1_xyz |
applepie |
ab%_xyz |
abcs_123_xyz |
aabc123 |
Output Code:
Snowflake¶
Results¶
COLUMN_NAME |
|---|
abc_123 |
a_cdef |
bxyz |
abcc |
apple |
banana |
abc cccc |
abc%def |
abc_xyz |
abc_1_xyz |
applepie |
ab%_xyz |
abcs_123_xyz |
aabc123 |
Escape characters¶
The following characters will be escaped if they appear in the pattern and are not the escape character itself:
.
$
^
Input Code:¶
Redshift¶
Results¶
COLUMN_NAME |
|---|
abc_123 |
abc_xyz |
abc_1_xyz |
R1 |
|---|
TRUE |
Output Code:
Snowflake¶
Results¶
COLUMN_NAME |
|---|
abc_123 |
abc_xyz |
abc_1_xyz |
R1 |
|---|
TRUE |
Pattern stored in a variable¶
If these patterns are stored in a variable, the required adjustments for equivalence will not be applied. You can refer to the recommendations outlined in the table at the beginning of this document for additional equivalence guidelines.
Input Code:¶
Redshift¶
Results¶
COLUMN_NAME |
|---|
abc_123 |
abcc |
xyzabc |
abc cccc |
abccc |
abc%def |
abc_xyz |
abc_1_xyz |
start%_abc |
abcs_123_xyz |
aabc123 |
123abc another line abc123 |
Output Code:
Snowflake¶
Results¶
COLUMN_NAME |
|---|
Query produced no results |
Usage of collate columns¶
Arguments with COLLATE specifications are not currently supported in the RLIKE function. As a result, the COLLATE clause must be disabled to use this function. However, this may lead to differences in the results.
Input Code:¶
Redshift¶
Results¶
CI |
CS |
|---|---|
TRUE |
FALSE |
Output Code:
Snowflake¶
Results¶
CI |
CS |
|---|---|
FALSE |
FALSE |
If you require equivalence for these scenarios, you can manually add the following parameters to the function to achieve functional equivalence:
Parameter |
Description |
|---|---|
|
Case-sensitive matching |
|
Case-insensitive matching |
Known Issues¶
The behavior of fixed char types may differ.
The
RLIKEfunction uses POSIX extended regular expressions, which may result in different behavior in certain cases, especially when line breaks are involved. It appears that when line breaks are present in the string and a match occurs on one line, it returns a positive result for the entire string, even though the match only occurred on a single line and not across the whole string. For example:
Redshift code¶
Snowflake code¶
Redshift Results¶
COL1 |
|---|
abcccc |
abc eab |
abc ccc |
Snowflake Results¶
COL1 |
|---|
abcccc |
To achieve maximum equivalence, some modifications are made to the pattern operators.
If these patterns are stored in a variable, SnowConvert AI does not apply the necessary adjustments for equivalence.
Arguments with COLLATE specifications are not currently supported in the RLIKE function.
Related EWIs¶
SSC-FDM-0032: Parameter is not a literal value, transformation could not be fully applied.
SSC-FDM-PG0011: The use of the COLLATE column constraint has been disabled for this pattern-matching condition.