Null option and Default value Lost when use CREATE TABLE AS to backup a table. - Mailing list pgsql-bugs

From Xiao, Bing (Benny)
Subject Null option and Default value Lost when use CREATE TABLE AS to backup a table.
Date
Msg-id DM5PR0101MB3002C39B637255E03599448AF9BF9@DM5PR0101MB3002.prod.exchangelabs.com
Whole thread Raw
Responses Re: Null option and Default value Lost when use CREATE TABLE AS to backup a table.  (Vik Fearing <vik@postgresfriends.org>)
Re: Null option and Default value Lost when use CREATE TABLE AS to backup a table.  (Francisco Olarte <folarte@peoplecall.com>)
List pgsql-bugs

Hi Team,

 

Null option(NOT NULL) and Default value lost when I try to copy a table with CREATE TABLE AS statement.

 

List the test step as below.

  1. PostgreSQL version.

 

 

  1. Create test table as below.

 

CREATE TABLE contact(

    id SERIAL PRIMARY KEY,

    first_name VARCHAR NOT NULL DEFAULT 'Benny',

    last_name VARCHAR NOT NULL,

    email VARCHAR NOT NULL UNIQUE

);

 

  1. Insert the test data to table Contact.

 

INSERT INTO contact(first_name, last_name, email)

VALUES('John','Doe','john.doe@postgresqltutorial.com'),

      ('David','William','david.william@postgresqltutorial.com');

 

  1. Create back up table.

 

               create table contact_bckp as table contacts with data;

 

  1. Test to insert data with null in column last_name. Failed in table contact.

 

INSERT INTO contact(first_name, last_name, email) VALUES('benny',null,'john.doe@postgresqltutorial.com');

 

 

  1. Test to insert data with null in column last_name. Succeed  in table contact_bckp. And even the PK column been set to null.

 

       INSERT INTO contact_bckp(first_name, last_name, email)  VALUES('benny',null,'john.doe@postgresqltutorial.com');

  1. Check the table definition as below. contact_bckp lost null option and default value compare to table contact.

 

 

Best Regards.

Benny

Email:  bing.xiao@dxc.com



Attachment

pgsql-bugs by date:

Previous
From: "David G. Johnston"
Date:
Subject: Re: BUG #17235: PQsendQuery (with two sql) after PQenterPipelineMode cause ERROR
Next
From: PG Bug reporting form
Date:
Subject: BUG #17240: at time zone ... ; wrong result