Redshift SQL 可以执行不区分大小写的正则表达式评估吗?
Can Redshift SQL perform a case insensitive regular expression evaluation?
文档说 regexp_instr() 和 ~ 区分大小写 Posix 计算函数和运算符。
是否有不区分大小写的 Posix 语法,或基于 PCRE 的函数或运算符
的插件
在 Redshift 查询中尝试的 PCRE 示例,由于 POSIX'ness 而无法按预期工作。
select
A.target
, B.pattern
, regexp_instr(A.target, B.pattern) as rx_instr_position
, A.target ~ B.pattern as tilde_operator
, regexp_instr(A.target
, 'm/'||B.pattern||'/i') as rx_instr_position_icase
from
( select 'AbCdEfffghi' as target
union select 'Chocolate' as target
union select 'Cocoa Latte' as target
union select 'coca puffs, delivered late' as target
) A
,
( select 'choc.*late' as pattern
union select 'coca.*late' as pattern
union select 'choc\w+late' as pattern
union select 'choc\w+late' as pattern
) B
回答您的问题:据我所知,没有与 Redshift 兼容的语法或插件。如果您可以使用解决方法:我们最终在字符串周围使用 lower()
来匹配:
select
A.target
, B.pattern
, regexp_instr(A.target, B.pattern) as rx_instr_position
, A.target ~ B.pattern as tilde_operator
, regexp_instr(A.target, 'm/'||B.pattern||'/i') as rx_instr_position_icase
, regexp_instr(lower(A.target), B.pattern) as rx_instr_position_icase_by_lower
from
( select 'AbCdEfffghi' as target
union select 'Chocolate' as target
union select 'Cocoa Latte' as target
union select 'coca puffs, delivered late' as target
) A
,
( select 'choc.*late' as pattern
union select 'coca.*late' as pattern
union select 'choc\w+late' as pattern
union select 'choc\w+late' as pattern
) B
Redshift 现在通过添加的函数参数为 case-insensitive 正则表达式标志提供直接解决方案:Amazon Redshift - REGEXP_INSTR
使用提供的查询示例的语法为:
select
A.target
, B.pattern
, regexp_instr(A.target, B.pattern) as rx_instr_position
, A.target ~ B.pattern as tilde_operator
, regexp_instr(A.target, B.pattern, 1, 1, 0, 'i') AS rx_instr_position_icase
from
( select 'AbCdEfffghi' as target
union select 'Chocolate' as target
union select 'Cocoa Latte' as target
union select 'coca puffs, delivered late' as target
) A
,
( select 'choc.*late' as pattern
union select 'coca.*late' as pattern
union select 'choc\w+late' as pattern
union select 'choc\w+late' as pattern
) B
select 'HELLO' ~* 'el'
= 真
目前没有记录 (2020-11-05)
文档说 regexp_instr() 和 ~ 区分大小写 Posix 计算函数和运算符。 是否有不区分大小写的 Posix 语法,或基于 PCRE 的函数或运算符
的插件在 Redshift 查询中尝试的 PCRE 示例,由于 POSIX'ness 而无法按预期工作。
select
A.target
, B.pattern
, regexp_instr(A.target, B.pattern) as rx_instr_position
, A.target ~ B.pattern as tilde_operator
, regexp_instr(A.target
, 'm/'||B.pattern||'/i') as rx_instr_position_icase
from
( select 'AbCdEfffghi' as target
union select 'Chocolate' as target
union select 'Cocoa Latte' as target
union select 'coca puffs, delivered late' as target
) A
,
( select 'choc.*late' as pattern
union select 'coca.*late' as pattern
union select 'choc\w+late' as pattern
union select 'choc\w+late' as pattern
) B
回答您的问题:据我所知,没有与 Redshift 兼容的语法或插件。如果您可以使用解决方法:我们最终在字符串周围使用 lower()
来匹配:
select
A.target
, B.pattern
, regexp_instr(A.target, B.pattern) as rx_instr_position
, A.target ~ B.pattern as tilde_operator
, regexp_instr(A.target, 'm/'||B.pattern||'/i') as rx_instr_position_icase
, regexp_instr(lower(A.target), B.pattern) as rx_instr_position_icase_by_lower
from
( select 'AbCdEfffghi' as target
union select 'Chocolate' as target
union select 'Cocoa Latte' as target
union select 'coca puffs, delivered late' as target
) A
,
( select 'choc.*late' as pattern
union select 'coca.*late' as pattern
union select 'choc\w+late' as pattern
union select 'choc\w+late' as pattern
) B
Redshift 现在通过添加的函数参数为 case-insensitive 正则表达式标志提供直接解决方案:Amazon Redshift - REGEXP_INSTR
使用提供的查询示例的语法为:
select
A.target
, B.pattern
, regexp_instr(A.target, B.pattern) as rx_instr_position
, A.target ~ B.pattern as tilde_operator
, regexp_instr(A.target, B.pattern, 1, 1, 0, 'i') AS rx_instr_position_icase
from
( select 'AbCdEfffghi' as target
union select 'Chocolate' as target
union select 'Cocoa Latte' as target
union select 'coca puffs, delivered late' as target
) A
,
( select 'choc.*late' as pattern
union select 'coca.*late' as pattern
union select 'choc\w+late' as pattern
union select 'choc\w+late' as pattern
) B
select 'HELLO' ~* 'el'
= 真
目前没有记录 (2020-11-05)