set_pk() attaches keys to x, so that collect_and_sort_by_pk() can
sort the result. DBTable_v9$tbl() calls it for every table. Call it for
a lazy table that you build yourself, for example from SQL text with
dplyr::sql(), when its rows have a primary key.
Arguments
- x
A lazy table.
- keys
A character vector with the primary key columns, or
NULL.NULLremoves the key, andcollect_and_sort_by_pk()then stops.
See also
Other row order:
collect_and_sort_by_pk(),
setorder_by_pk()
Examples
con <- DBI::dbConnect(RSQLite::SQLite(), ":memory:")
DBI::dbWriteTable(con, "t", data.frame(a = c(2L, 1L), b = c("y", "x")))
q <- set_pk(dplyr::tbl(con, dplyr::sql("SELECT a, b FROM t")), "a")
collect_and_sort_by_pk(q)
#> a b
#> <int> <char>
#> 1: 1 x
#> 2: 2 y
DBI::dbDisconnect(con)
