Learn R Programming

timeseriesdb (version 0.4.1)

runDbQuery: Run SELECT query

Description

Run database queries using dbSendQuery, fetch and dbClearResult in similar fashion as dbGetQuery but provide better error handling. This function always returns a data.frame as opposed to different types in case of an exception. However, if the database query fails and empty data.frame is returned. Besides query status and database error are returned as attributes. Make sure to use BEGIN and COMMIT outside of these statements.

Usage

runDbQuery(con, sql_query, ...)

Arguments

con

PostgreSQL connection object

sql_query

character string containing a SQL query

...

Additional arguments to be passed to dbGetQuery

Examples

Run this code
# NOT RUN {
# There's no connection, so this returns a proper error message.
# }
# NOT RUN {
out_obj <- runDbQuery(bogus_connection,"SELECT * FROM some_table") 
attributes(out_obj)
# }

Run the code above in your browser using DataLab