Skip to content

Why is dbWriteTable discouraged? #352

@pnacht

Description

@pnacht

The man page for dbWriteTable() discourages its use by stating that

New code should prefer dbCreateTable() and dbAppendTable().

However, I can't see why, given that it presents the same features and more in a tidy little function.

dbCreateTable() simply calls CREATE TABLE, without checking if the table already exists. So if one wishes to override a possibly-existing table, one must first call dbGetQuery("SELECT {table exists}") to determine whether the table exists, and then either dbExecute('DELETE FROM ...') if it does or dbCreateTable() if it doesn't, then dbAppendTable().

Or, you know, just call dbWriteTable(overwrite = TRUE). (And, if you want, add the row names as a column for "free")

In my ignorance, I can't seem to find the source code for dbWriteTable to understand what it does under the hood (I just found the default definition, which just looks like infinite recursion to me...), but I'd expect it has to do a lot of work to figure out precisely what it has to do in each situation.

So I understand that if the user knows they are creating a new table, they might be better served by dbCreate+AppendTable, which are clean pieces of code which likely outperform dbWriteTable for such tasks.

What I found odd was the term "New code", which implies dbWriteTable is inferior to the Create+Append combo, when it's seemingly a superset. Something like "However, a combination of dbCreateTable() and dbAppendTable() will in many cases be more performant".

Then again, I've usually found that there's something I've forgotten in these cases, so what haven't I taken into consideration here? Is it simply a maintenance attack-surface concern looking forward?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions