Regex SELECT和WHERE中的冗余正则表达式
有更好的方法吗?两次使用相同的正则表达式似乎很愚蠢,但我想指出哪个短语触发了所选的消息内容。Greenplum 4.2.2.4类似于服务器上的PostgreSQL 8.2Regex SELECT和WHERE中的冗余正则表达式,regex,postgresql,greenplum,Regex,Postgresql,Greenplum,有更好的方法吗?两次使用相同的正则表达式似乎很愚蠢,但我想指出哪个短语触发了所选的消息内容。Greenplum 4.2.2.4类似于服务器上的PostgreSQL 8.2 SELECT to_timestamp(extrainfo.startdate/1000) ,messages.timestamp ,users.username ,substring(messages.content from E'(?i)phrase number one|phrase\.two|another phras
SELECT
to_timestamp(extrainfo.startdate/1000)
,messages.timestamp
,users.username
,substring(messages.content from E'(?i)phrase number one|phrase\.two|another phrase|this list keeps going|lots\.of\*keyword phrases|more will be added in the future')
,messages.content
FROM users
LEFT JOIN messages ON messages.senderid = users.id
LEFT JOIN extrainfo ON extrainfo.username = users.username
WHERE extrainfo.type1 = 't'
AND messages.content ~* E'phrase number one|phrase\.two|another phrase|this list keeps going|lots\.of\*keyword phrases|more will be added in the future'
AND (extrainfo.type2 = 'f' OR extrainfo.type2 IS NULL)
尝试使用基本联接:
SELECT
to_timestamp(extrainfo.startdate/1000)
,messages.timestamp
,users.username
,substring(messages.content from rgxp.rgxp )
,messages.content
FROM users
LEFT JOIN messages ON messages.senderid = users.id
join (
select E'(?i)phrase number one|phrase\.two|another phrase|this list keeps going|lots\.of\*keyword phrases|more will be added in the future'::text
as rgxp
) rgxp
on messages.content ~* rgxp.rgxp
LEFT JOIN extrainfo ON extrainfo.username = users.username
WHERE extrainfo.type1 = 't'
AND (extrainfo.type2 = 'f' OR extrainfo.type2 IS NULL)
这只是一个表的演示:它真的是PostgreSQL 8.2古老版本还是您使用的是Greenplum还是Redshift?选择版本返回:PostgreSQL 8.2.15 Greenplum Database 4.2.2.4 build 1 Community Edition on x86_64-unknown-linux-gnu,由GCC 4.4.2编译,于2012年10月17日11:52:28如果您使用的是Greenplum,请不要说这是PostgreSQL。事实并非如此。这是Greenplum数据库。它的特性和功能与真正的PostgreSQL非常不同。我帮你解决了你的问题。很高兴知道。我不是DBA,所以我不知道。谢谢你的信息。谢谢你的建议。它似乎在某种程度上起作用,但没有完全填充子字符串列,大多数条目都返回为null。纠正和工作了!非常感谢你: