At my institution we often use R to query SQL databases and return data frames.
The code will look like this:
df<-dbGetQuery(jdbcConnection,
"select * from companydatabase.specificview")
The problem is, there's one view that's often empty. I.e. it exists, there are columns visible in SQL developer:
but often it's empty with zero rows. And so if I try to query it, I get an error.
So when figuring out how to prevent R from getting error when that happens, I have two possible avenues:
use
trycatch()
to handle errors and move past it (which I'm also going to do)make sure it always brings back at least one row, no matter what.
How do I do that (#2)? How do I just make sure I always get at least one blank row and the SQL doesn't error?