检查 table 中是否存在给定文本

Check existence of given text in a table

我有一个课程代码名称 COMP2221。

我还有一个函数 finder(int) 可以找到所有匹配特定模式的代码。

喜欢:

select * from finder(20004)

将给予:

comp2211
comp2311
comp2411
comp2221

匹配模式 comp2###.

我的问题是"whether comp2221 is in finder(20004)"如何表达得简洁?

How to express "whether comp2221 is in finder(20004)" in a neat way?

使用 EXISTS 表达式并将测试放入 WHERE 子句:

SELECT EXISTS (SELECT FROM finder(20004) AS t(code) WHERE code = 'comp2221');

Returns 单个 TRUEFALSE。绝不为 NULL 且绝不超过一行 - 即使您的 table 函数 finder() returns 重复。

或者fork函数finder()直接集成测试。可能更快。