-
Notifications
You must be signed in to change notification settings - Fork 185
Closed
Labels
bugan unexpected problem or unintended behavioran unexpected problem or unintended behaviorfunc trans 🌍Translation of individual functions to SQLTranslation of individual functions to SQLwipwork in progresswork in progress
Description
The LAG and LEAD functions do not have the default argument in Redshift. The dbplyr translation always inserts the default argument into the LEAD/LAG functions and this leads to an error in Redshift.
Please see below an example:
library(dbplyr)
library(DBI)
library(reprex)
con <- dbConnect(RPostgres::Redshift(),
host = "",
dbname = "",
port = ,
user = "",
password = )
# Create a simple table in the DB
table.sql <- sql("SELECT 1 AS YR, 1 AS MON, 123456 AS SALES
UNION ALL
SELECT 1 AS YR, 2 AS MON, 234567 AS SALES
UNION ALL
SELECT 1 AS YR, 3 AS MON, 345678 AS SALES
UNION ALL
SELECT 1 AS YR, 4 AS MON, NULL AS SALES
UNION ALL
SELECT 2 AS YR, 1 AS MON, 123456 AS SALES
UNION ALL
SELECT 2 AS YR, 2 AS MON, 234567 AS SALES
UNION ALL
SELECT 2 AS YR, 3 AS MON, 345678 AS SALES
UNION ALL
SELECT 3 AS YR, 1 AS MON, 123456 AS SALES
")
# Send query to DB creating the simple table
new.table <- con %>% dplyr::tbl(table.sql)
# Test lag and lead
new.table %>%
dbplyr::window_order(yr, mon) %>%
dplyr::mutate(LG = lag(sales), LD = lead(sales)) %>%
dplyr::arrange(yr, mon)
#> Error: Failed to prepare query: ERROR: Default parameter not be supported for window function lagCreated on 2020-11-26 by the reprex package (v0.3.0)
Redshift documentation links:
LAG: https://docs.aws.amazon.com/redshift/latest/dg/r_WF_LAG.html
LEAD: https://docs.aws.amazon.com/redshift/latest/dg/r_WF_LEAD.html
Metadata
Metadata
Assignees
Labels
bugan unexpected problem or unintended behavioran unexpected problem or unintended behaviorfunc trans 🌍Translation of individual functions to SQLTranslation of individual functions to SQLwipwork in progresswork in progress