0

I have my ODBC query to connect to Teradata and just wonder if I can read in the SQL file as oppose to have SQL code in? I am trying to find R function for Python's pd.read_sql_query(f, con) where f is my SQL file with code.

So for my connection, it would change from:

con <- function(){ query <- paste0(" SELECT * FROM table1 ") print(queryData(query)) } con<- data.frame(con()) 

to

con <- function(){ query <- "SQL_code.sql" print(queryData(query)) } con<- data.frame(con()) 
1
  • see dbGetQuery Commented Jul 23, 2020 at 7:31

2 Answers 2

0

read your sql from a file:

sql_query <- read.delim('/path/SQL_code.sql', header = FALSE) %>% as.character() 

then define the connection and use it:

library(DBI) db <- dbConnect(...) dbGetQuery(db, sql_query) 
Sign up to request clarification or add additional context in comments.

Comments

0

If I understand your question correctly, you could try something like this?

library(DBI) library(readr) df <- dbGetQuery(con, statement = read_file('SQL_code.sql')) # con is your connection 

If it does not solve your problem, there may be some solutions here: How to read the contents of an .sql file into an R script to run a query?

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.