Skip to content

Faulty SQL code from case_match. #1143

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
lschneiderbauer opened this issue Feb 9, 2023 · 1 comment · Fixed by #1144
Closed

Faulty SQL code from case_match. #1143

lschneiderbauer opened this issue Feb 9, 2023 · 1 comment · Fixed by #1144

Comments

@lschneiderbauer
Copy link

Good morning,

when experimenting with the new case_match, I noticed that I need to pass the criteria on the LHS as a vector, otherwise faulty SQL is generated (since those expressions are not enclosed in single quotation marks in this case). See the following reprex.

Is this intentional, or a bug?

library(dplyr, warn.conflicts = FALSE)
library(dbplyr, warn.conflicts = FALSE)

table <- tbl_lazy(tibble(col1 = c(1, 2), col2 = c(1, 2)), dbplyr::simulate_hana())

table %>%
  mutate(
    test =
      case_match(
        col1,
        "pos_1" ~ 1L, # does not work
        "pos_2" ~ 2L, # does not work
        c("pos_3") ~ 3L, # does work
        c("pos_4") ~ 4L  # does work
      )
  )
#> <SQL>
#> SELECT
#>   *,
#>   CASE
#> WHEN (`col1` IN (pos_1)) THEN 1
#> WHEN (`col1` IN (pos_2)) THEN 2
#> WHEN (`col1` IN ('pos_3')) THEN 3
#> WHEN (`col1` IN ('pos_4')) THEN 4
#> END AS `test`
#> FROM `df`

Created on 2023-02-09 with reprex v2.0.2

@mgirlich
Copy link
Collaborator

mgirlich commented Feb 9, 2023

Thanks, I only tested with integer vectors and single integers, not with a string 🤷

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants