Skip to content

This is an alternative to copy_to() that does not need write access and is faster for small data.

Usage

copy_inline(con, df)

Arguments

con

A database connection.

df

A local data frame. The data is written directly in the SQL query so it should be small.

Value

A tbl_lazy.

Details

It writes the data directly in the SQL query via the VALUES clause.

See also

copy_to() to copy the data into a new database table.

Examples

df <- data.frame(x = 1:3, y = c("a", "b", "c"))
con <- DBI::dbConnect(RSQLite::SQLite(), ":memory:")

copy_inline(con, df)
#> # Source:   SQL [3 x 2]
#> # Database: sqlite 3.38.5 [:memory:]
#>       x y    
#>   <int> <chr>
#> 1     1 a    
#> 2     2 b    
#> 3     3 c    

copy_inline(con, df) %>% dplyr::show_query()
#> <SQL>
#> SELECT CAST(`x` AS INTEGER) AS `x`, CAST(`y` AS TEXT) AS `y`
#> FROM (
#>   SELECT NULL AS `x`, NULL AS `y`
#>   WHERE (0 = 1)
#>   UNION ALL
#>   VALUES (1, 'a'), (2, 'b'), (3, 'c')
#> ) AS `values_table`