为什么在 PostgreSQL 中使用 ANY 运算符时会出现语法错误?

问题描述 投票:0回答:1

我在psql中创建了一个名为

restraunts
的表来显示所有朋友都去过的其余部分。这是表格(朋友和休息是列名称):

enter image description here

select distinct rest
from restraunts
where friends ilike any ('Micheal','Martin','Jack') and rest ilike any ('Ofelia','Casablanca');

我运行代码,但出现错误:

ERROR:  syntax error at or near ","
LINE 3: where friends ilike any('micheal','martin','jack') and rest ...
                                         ^

错误显示在逗号处。

为什么会发生这种情况以及如何解决?

sql postgresql psql any
1个回答
0
投票

查询中的问题是使用

ILIKE
运算符与
ANY
子句结合使用。您尝试直接将
ILIKE
运算符与值列表一起使用,但这不是正确的语法

正确的做法是:

SELECT DISTINCT rest
FROM restraunts
WHERE friends ILIKE ANY(ARRAY['Micheal', 'Martin', 'Jack']) AND rest ILIKE ANY(ARRAY['Ofelia', 'Casablanca']);
© www.soinside.com 2019 - 2024. All rights reserved.