Suppose I have a connection to an external database called con
.
I would like to use dplyr
to reproduce this query
SELECT var1, var2, var3 from myTable LIMIT 10
I have tried
qry <- tbl(con, "myTable") %>%
select(var1) %>%
filter(between(row_number(), 1, 10)
but it does not give the desired result and the query it produces is much slower than the one I am after.
The query it produces is
SELECT "var1",
FROM SELECT "var1", row_number() OVER () AS "zzz25"
FROM SELECT "var1" AS "var1"
FROM myTable "yhydrqlhho") "zsdfunxidf"
WHERE zzz25 BETWEEN 1.0 AND 10.0)
When I send this query to the database it runs for a very long time. When I send
SELECT var1 from myTable limit 10
the result comes back instantaneously.