Context
I have a PostgreSQL database structure with a table1 defined with many project specific fields (which are empty now, but which will get written through an application):
I have another table, let's say table3, already populated with (many) records of base data:
I'd like to append, in a column-wise manner, all the columns from table3 into table1.
These columns do not exists yet in table1.
The desired results would by as follows:
Question
How to achieve this in a nice way?
What I've tried so far
I have tried to follow this, but without success because the columns defined in table3 do not exist in table1:
UPDATE table1 a
SET (fid, attrib1, attrib2, attrib3, ...)
=
(b.fid, b.attrib1, b.attrib2, b.attrib3, ...)
FROM table3 b
;
I also tried using an `INSERT` statement:
INSERT INTO table1
SELECT fid, attrib1, attrib2, attrib3, ...
FROM table3;
But here I face this (obvious error):
ERROR: INSERT has more expressions than target columns
The third way I was thinking about was to ALTER table1 and add all new columns, one by one, which would be tedious because of the datatype definition (which I don't want to care about because it's already defined in table3). There is probably a smarter way of doing that.



table1.idandtable3.fidare primary/unique? Does some value for these fields may exist in one of tables and not exist in another? if true - what result do you need for such value? – Akina Apr 17 '20 at 11:43idandfidused to be serial (pkey) buttable1is empty now, soidwould be generated automatically(?). And the newtable1.fidcolumn can simply be an integer for the moment. Yes, I'd liketable1to be updated with the column-wise structure fromtable3and their respective data. All originaltable1columns will be updated after the desired concatenate operation occurred, but I will probably have to refreshtable1whentable3gets updated in the future. I don't know yet. – s.k Apr 17 '20 at 11:48table3content... – Akina Apr 17 '20 at 11:57