Skip to content

Faulty SQL code from case_match. #1143

Closed

Description

@lschneiderbauer

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

Activity

  1. mgirlich commented on Feb 9, 2023

    @mgirlich
    Collaborator

    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

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