sql - creating table as select is dropping the not null constraints in postgresql -


in postgres sql creating table select dropped not null constraints on table.

for example :

create table (char not null); create table b select * a; select * b;-- no constraint copied table 

please let me know how copy table data constraints in postgres.

there no single-command solution this.

to create table based on existing one, including constraints, use:

create table b ( including constraints); 

once have done that, can copy data old 1 new one:

insert b select * a; 

if in single transaction, looks atomic operation other sessions connected database.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -