Re: Default column value

From: "Joshua D(dot) Drake" <jd(at)commandprompt(dot)com>
To: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>, Rich Shepard <rshepard(at)appl-ecosys(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Default column value
Date: 2016-12-30 17:11:57
Message-ID: 6f09765e-d791-af49-c3f5-fd1bfba172da@commandprompt.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2016-12-30 21:46:48 Re: Default column value [ANSWERED]
Previous Message Karsten Hilbert 2016-12-30 17:05:12 Re: LYDB: Feasible to use PG roles instead of application-level security?