PostgreSQL,选择空字段 [英] Postgresql, select empty fields

查看:99
本文介绍了PostgreSQL,选择空字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从我的表中获取空的文本字段,该字段是我使用pgadmin手动清除的。
最初在那些字段中是,我可以这样查询它们:

I'm trying to get empty "text" fields from my table which I cleared manually with pgadmin. Initially in those fields was '' and I can query them like this:

SELECT mystr, mystr1 FROM mytable WHERE mystr='' or mystr1=''

但是如果我从其中删除文本并离开,则无法使用单元格为空。

But that not work if I delete text from them and leave cells blank.

如何编写查询以获取这些''并清除结果单元格?
还是仅清除单元格?

How to write query to get those '' and clear cells together in result? Or clear cells alone?

推荐答案

SELECT mystr, mystr1 
FROM mytable 
WHERE COALESCE(mystr, '') = '' 
   OR COALESCE(mystr1, '') = ''
    ;

说明: coalesce(a,b,c,...) 函数从左到右遍历列表 a,b,c,... 并在第一个非null元素处停止。 a,b,c 可以是任何表达式(或常量),但必须产生相同的类型(或可强制转换为相同的类型)。

Explanation: the coalesce(a,b,c, ...) function traverses the list a,b,c,... from left to right and stops at the first non-null element. a,b,c can be any expression (or constant), but must yield the same type (or be coercable to the same type).

这篇关于PostgreSQL,选择空字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆