Skip to content

dbplyr::copy_inline with MariaDB produces invalid SQL #1188

Closed
@avsdev-cw

Description

@avsdev-cw

As per title, I'm using MariaDB 10.5.18. Removal of the "ROW" from the reprex sql makes the query valid.

I've traced it back to a parameter of sql_values_subquery_default in verb-copy-to.R; row = TRUE for MariaDBConnection:

> dbplyr:::sql_values_subquery.MariaDBConnection
function (con, df, types, lvl = 0, ...) 
{
    sql_values_subquery_default(con, df, types = types, lvl = lvl, 
        row = TRUE)
}

dpkg:

ii  libmariadb-dev                           1:10.5.18-0+deb11u1                    amd64        MariaDB database development files
ii  libmariadb-dev-compat:amd64              1:10.5.18-0+deb11u1                    amd64        MariaDB Connector/C, compatibility symlinks
ii  libmariadb3:amd64                        1:10.5.18-0+deb11u1                    amd64        MariaDB database client library
ii  mariadb-client-10.5                      1:10.5.18-0+deb11u1                    amd64        MariaDB database client binaries
ii  mariadb-client-core-10.5                 1:10.5.18-0+deb11u1                    amd64        MariaDB database core client binaries
ii  mariadb-common                           1:10.5.18-0+deb11u1                    all          MariaDB common configuration files
ii  mariadb-server-10.5                      1:10.5.18-0+deb11u1                    amd64        MariaDB database server binaries
ii  mariadb-server-core-10.5                 1:10.5.18-0+deb11u1                    amd64        MariaDB database core server files
global <- list(
  db = list(
    host = "127.0.0.1",
    port = 3306,
    name = "DATABASE",
    user = "USER",
    password = "PASSWORD"
  )
)
conn <- DBI::dbConnect(
    RMariaDB::MariaDB(),
    host = global$db$host,
    port = global$db$port,
    dbname = global$db$name,
    user = global$db$user,
    password = global$db$password
  )
conn
#> <MariaDBConnection>
#>   Host:    127.0.0.1
#>   Server:  
#>   Client:
new_rows <- tibble::tibble(col_B = c("value_1", "value_2"))
qry <- dbplyr::copy_inline(conn, new_rows)
dplyr::show_query(qry)
#> <SQL>
#> SELECT CAST(`col_B` AS CHAR) AS `col_B`
#> FROM (
#>   (
#>     SELECT NULL AS `col_B`
#>     WHERE (0 = 1)
#>   )
#>   UNION ALL
#>   (VALUES ROW('value_1'), ROW('value_2'))
#> ) `values_table`
dplyr::collect(qry)
#> Error in `dplyr::collect()`:
#> ! Failed to collect lazy table.
#> Caused by error:
#> ! You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'ROW('value_1'), ROW('value_2'))
#> ) `values_table`' at line 8 [1064]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions