Questions tagged [dbi]
DBI is a database access module for the Perl programming language. It defines a set of methods, variables, and conventions that provide a consistent database interface, independent of the actual database being used. For the equivalent R package, use the tag r-dbi.
1,302
questions
0
votes
1
answer
44
views
Return value from cursor FOR LOOP calculation using DBI
I'm trying to understand how to return a calculated value from a SQL query that involves a cursor FOR LOOP using DBI. As an example, I use the mtcars dataset loaded into an Oracle database (v19c). It ...
0
votes
0
answers
36
views
Cannot connect to SQL Server Express but I can with SQL Management Studio
I have launched a SQL Server Express container via docker-compose. This launches all fine and I can connect with my locally installed SQL Management Studio using the credentials. But when I try to ...
0
votes
1
answer
16
views
Using RPostgres, what should I use to "set role..." for the table I will write to a db?
I'm new to connecting to databases via R, and I am trying to find best practices to minimize errors and problems. I am uploading a table from R to a postgres database, and I need to set the ...
1
vote
0
answers
23
views
R DBI issue with accessing list fields of a remote table
I am trying to get the fields of a table in an Arctic database. For that I've been successful at creating a jdbcConnection object which is of class "JDBCConnection", but once I write the ...
1
vote
0
answers
28
views
String length limitation using dbBind of DBI in R
I want to use DBI::dbBind to run some parameterized queries to update a SQL Server database but the string values I wrote got truncated at 256 characters. In the code below, I am supposed to see a ...
1
vote
1
answer
35
views
R: Update a mysql table with data frame
I have a MariaDB and I want to update a table with a local R data frame. As an example, I have a table with these column names:
id,foo,bar
id is the primary key on the data base table.
Is there a ...
0
votes
1
answer
38
views
Syntax error in SQL code being used in R, no row_number function found
I am using RSQLite, DBI, and dbplyr packages. I'm watching this YouTube video by TechTFQ.
library(dbplyr)
library(RSQLite)
library(DBI)
mtcars <- tibble::as_tibble(mtcars, rownames = 'car')
...
0
votes
1
answer
32
views
R using RSQLite, DBI and dbplyr, can't have more than one table in the RSQLite in order to make a join
I'm having a hard time understanding the behavior of these three packages: RSQLite, DBI, and dbplyr.
I'm using the mtcars dataframe and I'm loading it with the tibble package to add the car name as ...
1
vote
1
answer
38
views
R trouble finding the table in sql database from a function in DBI package, using with RSQLite and dbplyr
I have been studying a YouTube video from Andrew Couch about RSQLite, DBI, and dbplyr packages. Here is the link.
I'm running into an error, however, and I'm not sure what is happening. The YouTube ...
0
votes
1
answer
41
views
Connect R to Athena with ODBC Driver on MacOS
I'm trying to access data on Athena from R using ODBC.
I installed unixODBC via brew and the Simba Athena ODBC Driver from the web.
When I run :
con <- DBI::dbConnect(
odbc::odbc(),
Driver = &...
0
votes
0
answers
37
views
How to save to pre-existing Snowflake table from R using pool
I am using pool to handle connections to my Snowflake warehouse. I have created a connection to my database and can read data in a pre-existing table with no issues e.g:
my_pool <- dbPool(odbc::...
0
votes
1
answer
67
views
SQL Joining Tables from 2 Different Servers: R vs SAS
I have set up two different connections in R:
connection_1 <- dbConnect(odbc::odbc(), driver = my_driver, database = "database_1", uid = "my_id", pwd = "my_pwd", ...
0
votes
1
answer
47
views
Connect R to DB ORA -12560
I've the error ORA - 12560 when I try connect to Oracle DB installed on VM.
sql*plus, pl/sql, excel - connect successfully
Сonnection code in R
con <- dbConnect(odbc::odbc(), driver ='Oracle in ...
2
votes
1
answer
76
views
R SQL templating with glue_sql, ability to dynamically drop where clause
TLDR
I would like to be able to template SQL queries and run them in R. The glue package and DBI work great, but I can't figure out a way to template statements. In other words, is there a way to do ...
0
votes
0
answers
23
views
Specify another Windows account than session one when using DBI::dbConnect() and MS SQL Windows Authentication?
I am in a corporate environment.
I can easily establish a connection between R and a SQL database thanks to DBI and odbc packages this way:
con <- DBI::dbConnect(
odbc::odbc(),
driver = SQL....
1
vote
1
answer
92
views
R bigrquery: Exceeded rate limits
I am trying to download a BigQuery data set from Google Cloud Platform into R workspace in order to analyze it, using the following code:
library(bigrquery)
library(DBI)
library(tidyverse)
library(...
0
votes
0
answers
51
views
Error writing to connection: No space left on device
I'm using R to write a table in a MySQL database. I never had any issues with it before, but somehow this error just appeared:
Error in write.table(escape(value[from:to, , drop = FALSE]), file = conb, ...
0
votes
2
answers
68
views
How do I combine year month date time into a single datetime column using DBI in R?
Here's an example of my source data csv, df:
Year : int 2005 2005 2005 2005 2005 2005 2005 2005 2005 2005 ...
Month : int 1 1 1 1 1 1 1 1 1 1 ...
DayofMonth :...
0
votes
0
answers
16
views
"Overriding" SQL Errors During R Uploads
I have this data set:
var_1 = rnorm(1000,1000,1000)
var_2 = rnorm(1000,1000,1000)
var_3 = rnorm(1000,1000,1000)
sample_data = data.frame(var_1, var_2, var_3)
I broke this data set into groups of 100 ...
0
votes
1
answer
65
views
"Tricking" an SQL Server to Accept a File from R
I have a file (roughly 1000000 rows and 15 columns) in my local environment in R, and I am trying to upload this file onto a SQL server:
library(odbc)
library(DBI)
library(RODBC)
dbWriteTable(...
0
votes
1
answer
44
views
Splitting a Dataset into Arbitrary Sections
I have this data set:
var_1 = rnorm(1000,1000,1000)
var_2 = rnorm(1000,1000,1000)
var_3 = rnorm(1000,1000,1000)
sample_data = data.frame(var_1, var_2, var_3)
I would like to split this data set into ...
1
vote
2
answers
50
views
Store new permanent table in schema using compute
I want to use dbplyr syntax to do some JOIN / FILTER operations on some tables and store the results back to the Database without collecting it first.
From what I read compute(..., temporary = FALSE, ...
1
vote
1
answer
48
views
Declaring variable in R for DBI query to MS SQL
I'm writing an R query that runs several SQL queries using the DBI package to create reports. To make this work, I need to be able to declare a variable in R (such as a Period End Date) that is then ...
2
votes
2
answers
121
views
Use variable with regex in string::str_detect in dbplyr SQL query
I would like to filter a SQL database based whether a regular expression appears within any column. I would like to specify the regex as a variable; however it is read as a literal string. I am having ...
2
votes
2
answers
182
views
How to use in and out bind variables with executemany in cx_Oracle in Python
I would like to use cx_Oracle with in and out bind variables with named placeholders with Cursor.exeutemany. After a lot of browsing and cul-de-sac-s I could not find a proper way.
This is what I ...
2
votes
1
answer
181
views
select into temporary table
I believe I should be able to do select * into #temptable from othertable (where #temptable does not previously exist), but it does not work. Assuming that othertable exists and has valid data, and ...
0
votes
1
answer
117
views
R mssql Invalid Connection String
I have a docker container that contains a database which I'm able to access with the user id and password below and am running into an error when attempting to connect using this code:
con <- DBI::...
0
votes
0
answers
42
views
Error in conducting SQL queries using RODBC or ODBC with DBI
I got an error when I was using RODBC (or ODBC and DBI) to conduct SQL queries.
The error message is
"Error in odbcQuery(channel, query, rows_at_time) :
'Calloc' could not allocate memory (...
0
votes
0
answers
56
views
Raster to polygon in PostGIS
I am trying to convert a raster PostGIS table to a polygon. I don't care about the raster values - I want to polygonize all pixels as long as they have a value. I figured I should use ...
3
votes
2
answers
109
views
DBD::SQLite Placeholder for integer value in HAVING clause
Since similar statements using DBD::mysql seem to work fine, where is my mistake in using a placeholder for an integer in a HAVING clause, when using DBD::SQLite as DBI driver?
#!/usr/bin/perl
use 5....
0
votes
0
answers
50
views
R SQL: Inner Joins with Different Date Formats (HY000 Error: Bad External Date Representation)
I am working with the R programming language.
I have the two following tables (located on a server): table_1 and table_2
table_1 has a date variable "Date_1" that has a variable type "...
0
votes
1
answer
58
views
R: Summary of SQL Tables
I am working with the R programming language.
Normally, when I want to get the summary of a table, I can use something like the "str()" function or the "summary()" function:
str(...
3
votes
1
answer
74
views
Avoid dynamic SQL generation when calling stored procedure on SQL server from R/DBI/ODBC
Using the profiler on SQL Server to monitor a stored procedure call via DBI/odbc, shows that dynamic SQL / prepared statement is generated :
con <- DBI::dbConnect(odbc::odbc(),...)
dbGetQuery(con, &...
0
votes
1
answer
52
views
Trying to bind a complex file name in a DBI insert place holder, but special characters get mangled
Guys I don't know if this is a bind problem, character set problem or something I haven't considered. Here's the challenge - the file system was written by some cd ripping software but the problem is ...
0
votes
1
answer
40
views
DBConnect to open SQLite in read-only mode in R
I'm working on converting a simple Python script to R to act as a template for connecting up to SQLite files. The data is on a NFS mount, and we've run into a few snags in setting up the original ...
1
vote
2
answers
431
views
R dbWriteTable More Than One Class Warning
I've had a working R script that uses the dbWriteTable command to write to a SQL Server table. It has worked well without issue for a while ... until the last few days.
Now when I run the dbWriteTable ...
0
votes
1
answer
30
views
How to change SET column name with variable in Postgresql through R?
I have a analytic table in Postgresql which consists of several columns namely, unbonding, clogging and dirty.
this column contains numbers.
I want to update a value +1 in the column according to the &...
0
votes
1
answer
72
views
How do you write a table to DB using DBI/dbplyr and preserve date field?
When I use {DBI} and {dbplyr} to write a table containing a date-type field to a database, the field is forced to a character. How do I make it write to the SQL Server database table as a date type?
...
0
votes
0
answers
96
views
When connecting R to Microsoft SQL Server, do you have to use a DSN?
I want to connect R to SQL Server so I can export some R data frames as tables to SQL Server.
From a few online tutorials, I've seen they use the RODBC package, and it seems that you first need to ...
2
votes
1
answer
78
views
Execute multiple SQL statements (read from file) in R using DBI and RSQLite
I have the following example code:
library(DBI)
library(RSQLite)
conn <- DBI::dbConnect(RSQLite::SQLite(), "test.sqlite" )
########
# ## This is the original code when reading from the ...
1
vote
3
answers
167
views
UTF-8 decoding when reading a MySQL column of type JSON (vs. TEXT), using Perl DBI + DBD::mysql
Here is the problem, in a working unit test. I think it's either a bug in DBI + DBD::mysql, with respect to how it handles MySQL JSON columns, or a bug in my brain.
use strict;
use warnings;
use utf8;...
2
votes
1
answer
72
views
How to efficiently paste many variables into a sql query (Rshiny)
I'm building a shiny app where the user could update a table in a database by editing a selected row in a DT:table.
The problem is that process can be time-consuming when the dt:table has many columns ...
0
votes
1
answer
49
views
Changing class from character to integer but retaining all the datas inside
q7 <- dbGetQuery(conn,
"SELECT TailNum AS TailNum, AVG(ontime.DepDelay) AS avg_delay, ontime.Year AS Year, planes.Year AS yearmade
FROM planes JOIN ontime USING(tailnum)
WHERE ontime.Cancelled ...
1
vote
0
answers
141
views
R Fatal error with RPostgreSQL + R + macOS Monterey
I am trying to connect to redshift database using R.
Since I upgraded my mac to Monterey I receive a message in R as
" R Session Aborted -R encountered a fatal error - the session was terminated&...
2
votes
1
answer
54
views
Increase connection attempt with DBI
I'm trying to build a Shiny application which will be connected to an unstable PostgreSQL Database with DBI. It works fine when the database is stable, but gives Whitelabel Error whenever the database ...
0
votes
0
answers
161
views
Cannot make a connection between R and Snowflake driver
Error: nanodbc/nanodbc.cpp:1021: 00000: [unixODBC][Driver Manager]Can't open lib 'SnowflakeDSIIDriver' : file not found
I am having issues with Snowflake ODBC driver that was set up on my M1 chip ...
2
votes
1
answer
60
views
R DBI bind variable performance
I am facing performance issues when using bind variables with DBI package. My original use case is with Postgres database, but for reproducibility, below I use in-memory SQLite that has exactly the ...
0
votes
1
answer
75
views
Connect SQL Server with RStudio and access data in the environment
I have a connection to a mysql server like this:
mydb <- DBI::dbConnect(
drv = MySQL(),
host = "host",
port = 1111,
user = "user_1",
password = "password",
...
0
votes
1
answer
142
views
How to append table in SQL using R?
I am now using odbc/dbplyr R packages to control database. Though I know I could use the function union to bind two tables by row, I don't know how to append one table to another without loading the ...
0
votes
0
answers
222
views
Failing to install VEP dependencies
I'm trying to install VEP, but am getting stuck installing its dependencies.
I try to install as suggested here https://www.ensembl.org/info/docs/tools/vep/script/index.html
cd ~/bin
git clone https://...