Skip to content
Advertisement

How to append two dataframes when column number differ in PostgreSQL in R

What I try to do is that bind rows in my PostgreSQL databes in matched columns like rbindlist‘s (from data.table) fill argument.

In short, the table I’d like to see in my database is like this;

I tried it in RPostgres in this way;

But it doesn’t work and fields an error because the second table (b) doesn’t have a column called col2.

How to append tables by only common columns ?

Thanks in advance.

Advertisement

Answer

I think you need to:

  1. identify which columns are missing,
  2. alter table those new columns into existence, and then
  3. upload the data, assuming all data in the first that are missing in the second are null-able.
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement