user1701545 user1701545 - 1 year ago 159
R Question

R command to check if table exists in an sql database

I'm using the

sqldf
R library to write to an sql database using the command:

dbWriteTable(db, table_id, as.data.frame(table_df))


where
db
is the sql database file,
table_id
is the name of the table to be saved in the sql database, and the data.frame corresponding to the
table_id
is
table_df
.

My question is how do I check if a table with a certain
table_id
already exists in the sql database, and if so I'll skip the
dbWriteTable
for that table.

Answer Source

My best guess is you're using the DBI package which does have a dbWriteTable function (probably you are loading DBI via another package; it has an impressive reverse dependencies list). Quickly glancing at its documentation, DBI also has the dbExistsTable function that does what you want.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download