I have tried the readLines
and the read.csv
functions but then don't work.
Here is the contents of the my_script.sql
file:
SELECT EmployeeID, FirstName, LastName, HireDate, City FROM Employees
WHERE HireDate >= '1-july-1993'
and it is saved on my Desktop.
Now I want to run this query from my R script. Here is what I have:
conn = connectDb()
fileName <- "C:\\Users\\me\\Desktop\\my_script.sql"
query <- readChar(fileName, file.info(fileName)$size)
query <- gsub("\r", " ", query)
query <- gsub("\n", " ", query)
query <- gsub("", " ", query)
recordSet <- dbSendQuery(conn, query)
rate <- fetch(recordSet, n = -1)
print(rate)
disconnectDb(conn)
And I am not getting anything back in this case. What can I try?
dbSendQuery(conn, "SELECT Emp...")
, are any rows returned there? Are you confident that this is a problem with the read-from-file part and not a data-is-not-present problem? – Haldi.sql
file. – Esculentpaste(readLines(...), collapse = " ")
with the same success. Since a.sql
file is merely a text file with a different file extension, there's nothing cosmic. Is it something to do with your use ofquery
versusquery2
? You don't show how you got to that second variable. – HaldireadLines(..., encoding="UTF-8")
? You may also want to look aticonv()
. – HaldiError in postgresqlExecStatement(conn, statement, ...) : RS-DBI driver: (could not Retrieve the result : ERROR: syntax error at or near "" LINE 1:  UTF-8 --get priority in stack - APPS UTF-8 UTF-...
– EsculentpostgresqlExecStatement
? why is this tagged withmysql
?) I suggest you redirect your research (and rephrase your question to be) on different encodings within a query, since this problem appears likely to not be able "reading from a file". – Haldi