Search Postgresql Archives

Re: Default column value

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.


--
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux