Skip to content
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

str_replace_all broken for redshift #446

Closed
kmishra9 opened this issue May 8, 2020 · 2 comments
Closed

str_replace_all broken for redshift #446

kmishra9 opened this issue May 8, 2020 · 2 comments
Labels
bug an unexpected problem or unintended behavior func trans 🌍 Translation of individual functions to SQL

Comments

@kmishra9
Copy link

kmishra9 commented May 8, 2020

Code that ran fine under past versions of dbplyr threw some errors. I'm assuming the changes made in the newest dbplyr changelog (1.4.3) probably created the issue? The error is in the generated SQL, which provides a 'g' to the position parameter of the regexp_replace function in Redshift.

Error: Error: Failed to prepare query: ERROR: invalid input syntax for integer: "g"

Reprex:

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

lf <- dbplyr::lazy_frame(x = "0.88", con = dbplyr::simulate_postgres())

lf %>% mutate(x_cleaned = str_replace_all(string = x, pattern = "\\.", replacement = ""))
#> <SQL>
#> SELECT `x`, REGEXP_REPLACE(`x`, '\.', '', 'g') AS `x_cleaned`
#> FROM `df`

Created on 2020-05-08 by the reprex package (v0.3.0)

@kmishra9
Copy link
Author

kmishra9 commented May 8, 2020

Separately, redshift seems to have an issue with the tick marks around x and responds with the error: Error: Failed to prepare query: ERROR: operator does not exist: ` character varying HINT: No operator matches the given name and argument type(s). You may need to add explicit type casts.. Removing them in the raw sql translation that I'm using to get around this error for now allows the code to run correctly (as does using double quotes instead of backticks)

@hadley
Copy link
Member

hadley commented May 15, 2020

str_replace_all() did not behave correctly in the previous version; it only replaced a single match. This appears to be because the Postgres and Redshift implementation of REGEXP_REPLACE differ in whether or not they perform 1 or all replacements.

@hadley hadley added bug an unexpected problem or unintended behavior func trans 🌍 Translation of individual functions to SQL labels May 15, 2020
@hadley hadley closed this as completed in 54ea038 Sep 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior func trans 🌍 Translation of individual functions to SQL
Projects
None yet
Development

No branches or pull requests

2 participants