Yes, but not with a single SQL
Code:
--create the tables
create table parent ( a serial not null, z int, primary key (a));
create table child ( a int REFERENCES parent(a), sal char(1));
--insert some stuff for test
insert into parent values (0, 10);
insert into parent values (0, 20);
insert into parent values (0, 30);
insert into child values (1, "N");
insert into child values (2, "Y");
insert into child values (3, "Y");
--Add the child columns to the parent table
alter table parent add sal char(1);
--Move the data from child to parent
update parent set sal=(select sal from child where parent.a=child.a) where 1=1;
--Check the parent table
select * from parent;
a z sal
1 10 N
2 20 Y
3 30 Y
--drop the child table
drop table child;
A second way:
Code:
--create the tables
create table parent ( a serial not null, z int, primary key (a));
create table child ( a int REFERENCES parent(a), sal char(1));
--insert some stuff for test
insert into parent values (0, 10);
insert into parent values (0, 20);
insert into parent values (0, 30);
insert into child values (1, "N");
insert into child values (2, "Y");
insert into child values (3, "Y");
--create new parant table
create table parent2 (a int not null, z int, sal char(1), primary key (a));
--Move the data from child/parent to new parent
insert into parent2
select parent.a, parent.z, child.sal
from parent
inner join child
on parent.a=child.a;
--change to serial
alter table parent2 modify a serial not null primary key;
--Check the new parent table
select * from parent2;
a z sal
1 10 N
2 20 Y
3 30 Y
--drop the child and old parent table
drop table child;
drop table parent;
--rename the new parent table
rename table parent2 to parent;