0

Here is my code:

dbSendQuery(con, "create table origdata (day1 numeric, day2 numeric, day3 numeric, day4 numeric, day5 numeric, day6 numeric, day7 numeric, day8 numeric, day9 numeric, day10 numeric);") #3.4 data=data.frame(origData) data[is.na(data)]=0 dbWriteTable(con, "origdata", value=origData, row.names =F,append = T) 

But I am getting the error : Error in postgresqlpqExec(new.con, sql4) : RS-DBI driver: (could not Retrieve the result : ERROR: column "X1" of relation "origdata" does not exist )

and part of my data frame for reference. enter image description here

How can I get it to read the values from my data frame in to the table origdata? I need the columns to have those labels.

3
  • 1
    Column names of the DB table and your data.frame must match. Commented Dec 12, 2020 at 20:25
  • Thank you that solved my problems! Commented Dec 12, 2020 at 20:40
  • Reconsider saving data in wide format inside an enterprise RDBMS like Postgres. Number-suffixed columns even tables are not optimal database design. Use one column for day indicator and another for its value in long, normalized format. Commented Dec 12, 2020 at 22:33

1 Answer 1

1

To be able to import your data.frame into an existing database table, column names will have to match the SQL schema.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.