检查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=?);