开发者

Doing a SQLite MATCH using only negated terms

开发者 https://www.devze.com 2023-02-19 21:43 出处:网络
I recently 开发者_高级运维found that this is impossible in SQLite: SELECT * FROM fruit WHERE fruit MATCH \'-apple\'

I recently 开发者_高级运维found that this is impossible in SQLite:

 SELECT * FROM fruit WHERE fruit MATCH '-apple'

Yet this is possible:

 SELECT * FROM fruit WHERE fruit MATCH 'pear -apple'

I tried this using FTS3 and FTS4 with the same results. Why does match require at least one non-negated term? And how do I work around this limitation? I need to return all fruits that don't match "apple"...that's it. Any ideas?


Something like this will work:

SELECT * FROM fruit 
WHERE fruit.oid NOT IN 
(
    SELECT oid FROM fruit WHERE fruit MATCH 'apple'
)


Why don't you simply invert the search?

select * from fruit where fruit NOT match 'apple'

You could use a EXCEPT clause:

select * from fruit except select * from fruit where fruit match 'apple';

but that might not be very efficient.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号