From: | Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com> |
---|---|
To: | Rich Shepard <rshepard(at)appl-ecosys(dot)com>, pgsql-general(at)postgresql(dot)org |
Subject: | Re: Default column value |
Date: | 2016-12-30 14:55:36 |
Message-ID: | 69a2cee6-8ebf-31f4-89f4-05b264229aef@aklaver.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On 12/30/2016 06:38 AM, Rich Shepard wrote:
> Reading the 9.6 docs suggests an answer to my question, but does not
> explicitly answer it, so I ask here.
>
> If a column has a default value specified does this mean the column
> cannot
> contain a NULL value? In other words, is DEFAULT <some_value> NOT NULL
> redundant?
Another way of looking at it:
test=> create table default_test_2(id int, fld_1 varchar DEFAULT 'test');
CREATE TABLE
test=> insert into default_test_2 values (1);
INSERT 0 1
test=> insert into default_test_2 values (2, NULL);
INSERT 0 1
test=> \pset
null 'NULL'
test=> select * from default_test_2 ;
id | fld_1
----+-------
1 | test
2 | NULL
(2 rows)
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.
>
> TIA,
>
> Rich
>
>
--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com
From | Date | Subject | |
---|---|---|---|
Next Message | Rich Shepard | 2016-12-30 15:18:33 | Re: Default column value |
Previous Message | Tom Lane | 2016-12-30 14:54:52 | Re: Default column value |