Re: [GENERAL] Default column value - Mailing list pgsql-general

From Joshua D. Drake
Subject Re: [GENERAL] Default column value
Date
Msg-id 6f09765e-d791-af49-c3f5-fd1bfba172da@commandprompt.com
Whole thread Raw
In response to Re: [GENERAL] Default column value  (Adrian Klaver <adrian.klaver@aklaver.com>)
List pgsql-general
On 12/30/2016 06:46 AM, Adrian Klaver wrote:
> On 12/30/2016 06:38 AM, Rich Shepard wrote:

> test=> \d default_test
>       Table "public.default_test"
>  Column |       Type        | Modifiers
> --------+-------------------+-----------
>  id     | integer           |
>  fld_1  | character varying |
>
>>

To further illustrate this, NULL means UNKNOWN, not DEFAULT. Using
Adrian's example:

postgres=# create table default_test(id int, fld_1 varchar DEFAULT NULL);
CREATE TABLE
postgres=# INSERT into default_test VALUES(1,NULL);
INSERT 0 1
postgres=# INSERT into default_test VALUES(1,DEFAULT);
INSERT 0 1
postgres=# select * from default_test ;
  id | fld_1
----+-------
   1 |
   1 |
(2 rows)

postgres=# alter table default_test alter column fld_1 set default now();
ALTER TABLE
postgres=# INSERT into default_test VALUES(1,DEFAULT);
INSERT 0 1
postgres=# INSERT into default_test VALUES(1,NULL);
INSERT 0 1
postgres=# select * from default_test ;
  id |             fld_1
----+-------------------------------
   1 |
   1 |
   1 | 2016-12-30 09:11:11.170948-08
   1 |
(4 rows)

Sincerely,

JD

--
Command Prompt, Inc.                  http://the.postgres.company/
                         +1-503-667-4564
PostgreSQL Centered full stack support, consulting and development.
Everyone appreciates your honesty, until you are honest with them.


pgsql-general by date:

Previous
From: Karsten Hilbert
Date:
Subject: Re: [GENERAL] LYDB: Feasible to use PG roles instead ofapplication-level security?
Next
From: Adrian Klaver
Date:
Subject: Re: [GENERAL] Default column value [ANSWERED]