检查PostgreSQL中是否存在行 [英] Check if a row exists or not in postgresql
本文介绍了检查PostgreSQL中是否存在行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在SO中看到了很多与此相关的帖子。但是我没有答案。
我想查询查询表中是否存在特定行。如果存在,它应该给我返回一个 string 真,并在那里停止搜索,否则就返回false。
I have seen many posts about this in SO. But I could not get an answer. I want to the query to check if a particular row exists or not in a table. If it exists, it should return me a string true and stop the search there itself and if not return false.
推荐答案
select
case when exists (select true from table_name where table_column=?)
then 'true'
else 'false'
end;
但是最好返回布尔值而不是字符串:
But it would be better to just return boolean instead of string:
select exists (select true from table_name where table_column=?);
这篇关于检查PostgreSQL中是否存在行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文