0

I have the following query:

query <- 'SELECT field1, field2
from mytable
where field1 IN $1
AND field2 <= $2
ORDER BY field1 ASC, field2 DESC;'

params <- list(list('A','B'), as.character(as.POSIXlt(Sys.time(), tz="UTC")))

print(params)

I run:

df <- dbGetQuery(conn, query, params=params)

And I get:

Error in postgresqlExecStatement(conn, statement, ...) : 
  RS-DBI driver: (could not Retrieve the result : ERROR:  there is no parameter $1
LINE 7: WHERE field1 IN ($1)
                                             ^
)

How can I use a /parameterized/ query with an IN in a WHERE clause in RPostgreSQL?

Mittenchops
  • 18,633
  • 33
  • 128
  • 246
  • 1
    You misunderstand the API. We just send strings so I fear you need to interpolate _before_ it hits the wire. Unless I keep forgetting some magic that was added later. – Dirk Eddelbuettel Dec 17 '19 at 21:31
  • Darn, as happens whenever I write R: I was banking on the present existence of some @DirkEddelbuettel magic. – Mittenchops Dec 17 '19 at 21:50

0 Answers0