SQL不是空的,而不是不是空的 [英] SQL Not Empty instead of Not NULL

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

问题描述

我正在使用postgreSQL.我有一列:

I am using postgreSQL. I have a column that:

NOT NULL

但是,当我想插入带有空字符串的行时,例如:

However when I want to insert a row with an empty string as like:

''

它不会给我错误并接受.如何检查插入值应为not empty? (既不为空也不为空)

it doesn't give me an error and accepts. How can I check insert value should be not empty? (Neither empty nor null)

PS:我的列定义为:

"ads" character varying(60) NOT NULL

推荐答案

向列定义添加约束.例如:

Add a constraint to column definition. For example something like:

ads character varying(60) NOT NULL CHECK (ads <> '')

有关更多信息,请参见 http://www.postgresql.org/docs/current/static/ddl-constraints.html

For more, see http://www.postgresql.org/docs/current/static/ddl-constraints.html

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

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