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.


