Re: Default column value

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Rich Shepard <rshepard(at)appl-ecosys(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Default column value
Date: 2016-12-30 16:29:07
Message-ID: CAKFQuwZa6K0qamC_YuoFZhKwgbTMokd2V8xpCS7yYStpR-wxsg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, Dec 30, 2016 at 9:19 AM, Rich Shepard <rshepard(at)appl-ecosys(dot)com>
wrote:

> On Fri, 30 Dec 2016, Adrian Klaver wrote:
>
> DEFAULT is what is the column is set to if the user does not specify a
>> value. As shown above a user can supply a NULL value. To guard against
>> that the NOT NULL constraint is required.
>>
>
> One more case I'd appreciate being clarified: when the column's value has
> a check constraint with acceptable values in a list. For example,
>
> param_units VARCHAR(8) DEFAULT 'mg/L'
> CONSTRAINT param_units
> CHECK (param_units IN ('ppm', 'mg/L', 'ug/L', 'umho/cm', 'percent',
> 'cfm', 'gpm')),
>
> Seems to me that if values are constrained by a list a NULL cannot be
> entered by the user. Is this correct?
>
>
​https://www.postgresql.org/docs/9.6/static/sql-createtable.html​

"The CHECK clause specifies an expression producing a Boolean result which
new or updated rows must satisfy for an insert or update operation to
succeed. Expressions evaluating to TRUE or UNKNOWN succeed."

NULL == "UNKNOWN"

David J.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Rich Shepard 2016-12-30 16:51:15 Re: Default column value [ANSWERED]
Previous Message Rich Shepard 2016-12-30 16:19:01 Re: Default column value