我正在使用PostgreSQL並希望阻止某些必需的CHARACTER VARYING(VARCHAR)字段允許空字符串輸入。阻止CHARACTER VARYING字段中的空字符串
這些字段也需要包含唯一值,所以我已經使用了一個唯一的約束;但是,這並不妨礙原始(唯一)空值。
基本例如,在用戶名必須是唯一的,而不是空
| id | username | password |
+----+----------+----------+
| 1 | User1 | pw1 | #Allowed
| 2 | User2 | pw1 | #Allowed
| 3 | User2 | pw2 | #Already prevented by constraint
| 4 | '' | pw2 | #Currently allowed, but needs to be prevented
https://en.wikipedia.org/wiki/Jeralean_Talley – OdraEncoded 2015-06-14 12:39:55