tidyverse / dbplyr

Database (DBI) backend for dplyr

Home Page:https://dbplyr.tidyverse.org

Repository from Github https://github.comtidyverse/dbplyrRepository from Github https://github.comtidyverse/dbplyr

Translation to REGEXP_INSTR errors in snowflake with options(dplyr.strict_sql = TRUE)

edward-burn opened this issue · comments

When setting options(dplyr.strict_sql = TRUE) on snowflake stringr::str_detect() errors, but it seems that the translation is working when I have this option set to FALSE with REGEXP_INSTR used. This does not seem to be an issue for str_replace which is translated to REGEXP_REPLACE.

library(dbplyr)
library(stringr)
options(dplyr.strict_sql = FALSE) 
translate_sql(str_detect(var, "b"),
              con = simulate_snowflake())
#> <SQL> REGEXP_INSTR(`var`, 'b') != 0
translate_sql(str_replace(var, "b", "c"),
              con = simulate_snowflake())
#> <SQL> REGEXP_REPLACE(`var`, 'b', 'c', 1.0, 1.0)
translate_sql(str_ends(var, "b"),
              con = simulate_snowflake())
#> <SQL> REGEXP_INSTR(`var`, 'b', 1, 1, 1) = (LENGTH(`var`) + 1)

options(dplyr.strict_sql = TRUE) 
translate_sql(str_detect(var, "b"),
              con = simulate_snowflake())
#> Error in `REGEXP_INSTR()`:
#> ! Don't know how to translate `REGEXP_INSTR()`
translate_sql(str_replace(var, "b", "c"),
              con = simulate_snowflake())
#> <SQL> REGEXP_REPLACE(`var`, 'b', 'c', 1.0, 1.0)
translate_sql(str_ends(var, "b"),
              con = simulate_snowflake())
#> Error in `REGEXP_INSTR()`:
#> ! Don't know how to translate `REGEXP_INSTR()`

Created on 2025-01-06 with reprex v2.1.0