Redshift LIKE列值,带% [英] Redshift LIKE column value with %

查看:124
本文介绍了Redshift LIKE列值,带%的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一列,它是用逗号分隔的值字符串.我想加入另一个只有一个值的表.在进行红移时,如何在比较中注入'%'来进行LIKE运算符?

I have a column that is a comma separated string of values. I want to join another table that only has one of the values. On redshift, how can I do a LIKE operator with '%' injected into the comparison?

例如:

TableA:values_col ='abc,def'

TableA: values_col = 'abc, def'

TableB:value_col ='def'

TableB: value_col = 'def'

SELECT *
FROM TableA a
JOIN TableB b ON b.value_col LIKE '%' || a.values_col || '%'

上面的concat似乎不起作用.任何建议,将不胜感激.谢谢.

The above concat doesn't seem to work. Any suggestions would be appreciated. Thanks.

推荐答案

您将获得出色的性能.您应该修复您的数据结构.但是如果必须的话,这应该可以工作:

You will get awful performance. You should fix your data structure. But if you have to, then this should work:

SELECT *
FROM TableA a JOIN
     TableB b
     ON ',' || a.values_col || ',' LIKE '%,' || b.value_col || ',%';

如果值之间可以包含逗号,则逗号很重要.更重要的是,like需要正确顺序的操作数.

The commas are important if your values can contain each other. More importantly, the like needs the operands in the right order.

这篇关于Redshift LIKE列值,带%的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆