rpostgresql

RPostgreSQL Cannot Close Connections

余生颓废 提交于 2021-02-18 07:26:33
问题 I have a shiny app that connects to a database using RPostgreSQL . At the end of the app the connection is closed and the driver should be unloaded but I get an error, warning me that the connection is not closed. The code looks something like this: # in the app.R file, but not in the server function: drv <- dbDriver("PostgreSQL") con <- dbConnect(drv, dbname = "database1", host = "localhost", port = 5432, user = "user", password = "pw") # in the server function: foo <- dbGetQuery(con,

How to write and read binary data with RPostgresql

吃可爱长大的小学妹 提交于 2020-01-07 03:00:39
问题 I am trying to execute the code: Connect to the server library('RPostgreSQL', quietly = TRUE) kHostName <- '...' kPort <- '5432' kDBName <- '...' kUser <- '...' kPassword <- '...' drv <- dbDriver("PostgreSQL") con <- dbConnect(drv, host = kHostName, port = kPort, dbname = kDBName, user = kUser, password = kPassword) The following part of the code is taken from https://groups.google.com/forum/#!topic/rpostgresql-dev/lPPmS8yeP9w and https://github.com/codeinthehole/rpostgresql/blob/master

Can I run an SQL update statement using only dplyr syntax in R

廉价感情. 提交于 2020-01-01 08:56:06
问题 I need to update column values conditionnaly on other columns in some PostgreSQL database table. I managed to do it writing an SQL statement in R and executing it with dbExecute from DBI package. library(dplyr) library(DBI) # Establish connection with database con <- dbConnect(RPostgreSQL::PostgreSQL(), dbname = "myDb", host="localhost", port= 5432, user="me",password = myPwd) # Write SQL update statement request <- paste("UPDATE table_to_update", "SET var_to_change = 'new value' ", "WHERE

R RPostgreSQL Connect to Remote Postgres Database with SSL

喜夏-厌秋 提交于 2019-12-30 08:50:12
问题 I am trying to connect to a remote PostgreSQL database from within R using the RPostgreSQL package, and I am getting errors that appear to be related to the SSL settings for the connection. I have verified that I can connect from the command line using psql , so I know the connection is valid and accessible from my computer. My first attempt at connecting in R was the following (where <MyHost> and <MyPass> were filled out appropriately for my connection): library(RPostgreSQL) pg <- dbDriver(

how to pass value stored in r variable to a column in where clause of postgresql query in R

时间秒杀一切 提交于 2019-12-24 04:29:13
问题 I am using RPostgresql and DBI in RStudio. library(RPostgreSQL) library(DBI) #save password prod_pw <- { "my_pass" } # make db connection con <- dbConnect(RPostgreSQL::PostgreSQL(), dbname = 'my_dbname', host = 'my_host', port = 5432, # or any other port user = 'user_name', password = prod_pw) # save query myquery<- 'select count(*), state from results where date=\'2018-11-10\';' #run query my_query_stats<-dbGetQuery(con,myquery) However I want to automate this, such a way that the date can

Using RMySQL interferes with RPostgreSQL

吃可爱长大的小学妹 提交于 2019-12-24 02:39:15
问题 I have an R script where I want to pull some data from a MySQL database, then from a PostgreSQL database. However, loading the MySQL driver from RMySQL prevents me from loading the PostgreSQL driver from PostgreSQL . I can load the Postgres driver fine on its own: > RPostgreSQL::PostgreSQL() <PostgreSQLDriver:(58810)> Then I can load the RMySQL driver: > RMySQL::MySQL() <MySQLDriver> However, if I load the MySQL driver first, the PostgreSQL driver fails to load: > RMySQL::MySQL() <MySQLDriver

I cannot connect postgresql schema.table with dplyr package

社会主义新天地 提交于 2019-12-20 09:18:14
问题 Im trying to connect postgres with dplyr functions my_db <- src_postgres(dbname = 'mdb1252', user = "diego", password = "pass") my_db src: postgres 9.2.5 [postgres@localhost:5432/mdb1252] tbls: alf, alturas, asociad, atenmed, base, bfa_boys_p_exp, bfa_boys_z_exp, bfa_girls_p_exp, bfa_girls_z_exp, bres, c21200012012, c212000392011, c212000532011, c21200062012, c212006222012, c212007352012, c212012112013, c212012242012, c212012452012, c2222012242012, calles, cap, cap0110, casos_tbc_tr09, casos

Can't create dbConnect to Postgres with SSL

99封情书 提交于 2019-12-19 09:04:26
问题 I'm running a Postgres-9.4 server that I would like to require SSL for. When I connect to the Postgres server from my laptop with either pgadmin or windows odbc connection, it works with SSL. However when I try to connect with R using SSL it fails. library(RPostgreSQL) drv <- dbDriver("PostgreSQL") con <- dbConnect(drv, user = "postgres", password = mypasswd, dbname = "dbname=postgres sslmode=prefer", host = "192.168.1.179") If I set my pg_hba.conf to allow non-ssl connections then this will

RPostgreSQL - Passing Parameter in R to a Query in RPostgreSQL

有些话、适合烂在心里 提交于 2019-12-19 04:57:10
问题 Question : How do I pass a variable in the RPostgreSQL query? Example : In the example below I try to pass the date '2018-01-03' to the query library(RPostgreSQL) dt <- '2018-01-03' connect <- dbConnect(PostgreSQL(), dbname="test", host="localhost", port=5432, user="user", password="...") result <- dbGetQuery(connect, "SELECT * FROM sales_tbl WHERE date = @{dt}") 回答1: You can use paste0 to generate your query and pass it to dbGetQuery: library(RPostgreSQL) dt <- '2018-01-03' connect <-

How to use parameters with RPostgreSQL (to insert data)

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-18 04:46:06
问题 I'm trying to insert data into a pre-existing PostgreSQL table using RPostgreSQL and I can't figure out the syntax for SQL parameters (prepared statements). E.g. suppose I want to do the following insert into mytable (a,b,c) values ($1,$2,$3) How do I specify the parameters? dbSendQuery doesn't seem to understand if you just put the parameters in the ... . I've found dbWriteTable can be used to dump an entire table, but won't let you specify the columns (so no good for defaults etc.). And