Fetching Data using RPostgreSQL Package in R



How can I Fetch the data from existing data frame in R using RPostgreSQL Package


Hi @Surya1987

you can use the function dbGetQuery( dbref, “SQL Query”) where dbref is the object that you get using dbConnect() and SQL Query is the Postgres type of SQL statement.

You can insert of your data frame with dbWriteTable(). One problem if you have warnings RPostgreSQL will not always trigger them.

Hope this help.



You can use RODBC package for this.
myServer <- "server_name"
myUser <- "user_name"
myPassword <- "pass"
myDatabase <- "mydb"
myDriver <- “SQL Server” # Must correspond to an entry in the Drivers tab of “ODBC Data Sources”

connectionString <- paste0(
“Driver=”, myDriver,
";Server=", myServer,
";Database=", myDatabase,
";Uid=", myUser,
";Pwd=", myPassword)
conn_local <- odbcDriverConnect(connectionString)

This query simulates a table by generating a rowset with one integer column going from 1 to 1000

sqlTables(conn_local) #will show all the tables from database
data<-sqlFetch(conn_local,“data”) # fetching_from_particular_table

if u want to use RPostgreSQL this package then u can try:

data<- dbSendQuery(conn_local , “select * from data”)

hope it will work;