How do I keep all escape characters in a SQL string for a POSTGRES database query using R?
I am using R to query data from Postgres database. The query I created in pgAdmin3 has a lot of escape characters in it and I would take the entire SQL string without having to deal with escape characters, sort of like Python triple quotes "".
SELECT brand
,regexp_replace(upper(hybridtype), '\(.*\)|\/|-|TM|\s','','g') as hybrid
FROM seeds
How can I get this SQL text in R while preserving all characters?
+3
source to share
1 answer
in PGAdmin, copy the text to the clipboard. Then in R:
sql_qry <- clipPaste()
If clipPaste is defined like this:
clipPaste <- function(flat=TRUE) {
con <- pipe("pbpaste", open = "rb")
ret <- readLines(con, warn = FALSE)
if (flat)
ret <- paste0(ret, collapse = "\n")
close(con)
return(ret)
}
All characters will be escaped accordingly.
+1
source to share