Skip to content

fill does not work with SQL server #651

Closed

Description

@nassuphis

fill does not work with SQL server

> tibble(x=c(1,2,3,NA,5,6,NA,NA),i=seq_along(x)) %>%
+ copy_to(name="test",dest=db_con,temporary=FALSE,overwrite=TRUE,append=FALSE) %>%
+ window_order(i) %>%
+ fill(x)  
Error: nanodbc/nanodbc.cpp:1655: 00000: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Incorrect syntax near 'IGNORE'.  [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Statement(s) could not be prepared. 
<SQL> 'SELECT TOP 11 "i", LAST_VALUE("x" IGNORE NULLS) OVER (ORDER BY "i") AS "x"
FROM "test"'

Activity

  1. mgirlich commented on May 7, 2021

    @mgirlich
    Collaborator

    Ah, it seems the IGNORE NULLS part should be outside of LAST_VALUE(). Can you check if your code works after you executed the following code

    `last_value_sql.Microsoft SQL Server` <- function(con, x) {
      build_sql("LAST_VALUE(", ident(as.character(x)), ") IGNORE NULLS", con = con)
    }
  2. nassuphis commented on May 7, 2021

    @nassuphis
    Author

    will do + revert.
    the whole dbplyr package is awesomely useful.
    thanks for the all the good work!

  3. mgirlich commented on Jul 7, 2021

    @mgirlich
    Collaborator

    Argh, seems like IGNORE NULLS is only supported by Azure SQL Edge

  4. fabkury commented on Dec 22, 2022

    @fabkury

    Same thing happens with Databricks ODBC connections:

    Error in new_result(connection@ptr, statement, immediate) : 
      nanodbc/nanodbc.cpp:1412: 42000: [Simba][Hardy] (80) Syntax or semantic analysis error thrown in server while executing query. Error message from server: org.apache.hive.service.cli.HiveSQLException: Error running query: org.apache.spark.sql.catalyst.parser.ParseException: 
    mismatched input 'IGNORE' expecting {')', ',', '-'}(line 21, pos 38)
    
    SELECT
          `row_id`,
          `pid`,
          `ts`,
          LAST_VALUE(`guia_total_cobrado` IGNORE NULLS) OVER (PARTITION BY `pid` ORDER BY `pid`, `ts`) AS `guia_total_cobrado`,
    --------------------------------------^^^
    

    I was able to make it work by running this prior to fill():

    `last_value_sql.Spark SQL` <- function(con, x) {
      dbplyr:::build_sql("LAST_VALUE(", ident(as.character(x)), ", true)", con = con)
    }
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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