I'm getting the following error when I apply a specific dplyr function distinct()
to a table in a SQL database.
tbl(P0_MAU_3N_V, "D_QNO_MTYPE") %>% distinct()
#> Error: <SQL> 'SELECT DISTINCT TOP 11 * FROM "D_QNO_MTYPE"'
#> nanodbc/nanodbc.cpp:1700: HY222: [Teradata][ODBC Teradata Driver]
#> [Teradata Database](-3419)
#> TOP N Syntax error: Top N option is not supported with DISTINCT option.
If I examine the query I get:
tbl(P0_MAU_3N_V, "D_QNO_MTYPE") %>% distinct() %>% show_query()
#> <SQL>
#> SELECT DISTINCT *
#> FROM "D_QNO_MTYPE"
I'm guessing this is some kind of no-no in SQL syntax. What's the best way to use dplyr::distinct()
on a SQL database? Is there a tidyverse way to do this or should this be some type of direct SQL query?
EDIT
@akrun I'm sorry but I just don't know how to make the repro, with the example you give. I hope this helps:
DBI::dbGetInfo(P0_MAU_3N_V)
#> $dbname
#> [1] "P0_MAU_3N_V"
#>
#> $dbms.name
#> [1] "Teradata"
#>
#> $db.version
#> [1] "15.10.0704 15.10.07.04"
#>
#> $username
#> [1] "redacted"
#>
#> $host
#> [1] ""
#>
#> $port
#> [1] ""
#>
#> $sourcename
#> [1] ""
#>
#> $servername
#> [1] "redacted"
#>
#> $drivername
#> [1] "tdataodbc_sb64.dll"
#>
#> $odbc.version
#> [1] "03.80.0000"
#>
#> $driver.version
#> [1] "16.20.00.054"
#>
#> $odbcdriver.version
#> [1] "03.80"
#>
#> $supports.transactions
#> [1] TRUE
#>
#> attr(,"class")
#> [1] "Teradata""driver_info""list"