PostgreSQL,选择空字段

编程入门 行业动态 更新时间:2024-10-25 06:20:17
本文介绍了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,选择空字段

本文发布于:2023-10-15 01:13:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1492806.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字段   PostgreSQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!