我需要将动态Where生成到PL/PGSQL函数中,例如:我有以下字符串
你好,postgresql,堆栈溢出
我需要执行以下查询:
SELECT * FROM tblname WHERE tbl_col LIKE %hello% OR tbl_col LIKE %postgresql% OR tbl_col LIKE %stackoverflow%;有什么方法可以用逗号分隔字符串并生成动态的where查询?
谢谢你的帮助。
发布于 2016-11-22 21:10:02
select *
from tblname
where tbl_col like any(array['%hello%', '%postgresql%', '%stackoverflow%']);发布于 2016-11-22 20:47:31
您可以使用类似的运算符,而不是喜欢。您可以找到文档这里
举个例子:
SELECT
*
FROM
tblname
WHERE
tbl_col SIMILAR TO '%(' || REPLACE( 'hello,postgresql,stackoverflow', ',', '|' )|| ')%'https://stackoverflow.com/questions/40751125
复制相似问题