Re: NOT NULL CHECK (mycol !='') :good idea? bad idea?

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Michael Moore <michaeljmoore(at)gmail(dot)com>
Cc: postgres list <pgsql-sql(at)postgresql(dot)org>
Subject: Re: NOT NULL CHECK (mycol !='') :good idea? bad idea?
Date: 2016-06-03 18:37:20
Message-ID: CAKFQuwa1C5EHj2jBL=Jbsx5sWd+EG325yC-VBsoM5Dg=vX5yaQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Fri, Jun 3, 2016 at 2:16 PM, Michael Moore <michaeljmoore(at)gmail(dot)com>
wrote:

> In Oracle, a NOT NULL constraint on a table column of VARCHAR in essence
> says: "You need to put at least 1 character for a value". There is no such
> thing as a zero-length string in Oracle, it's either NULL or it has some
> characters.
>
> To make Postgres perform an equivalent column edit, I am considering
> defining table columns like ... mycol VARCHAR(20) NOT NULL CHECK (mycol
> !='')
>
> Is there any drawback to this? Is there a better way to do it? Any
> thoughts? how about ....
> mycol VARCHAR(20) NOT NULL CHECK (length(mycol) > 0)
> or even
> mycol VARCHAR(20) CHECK (length(mycol) > 0)
>
>
​That seems like the best choice. Equality checks should be faster than
length detection.

Dave

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message David W Noon 2016-06-03 18:56:05 Re: NOT NULL CHECK (mycol !='') :good idea? bad idea?
Previous Message Michael Moore 2016-06-03 18:16:33 NOT NULL CHECK (mycol !='') :good idea? bad idea?