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_flatten does not work in Redshift #804

Closed
hdplsa opened this issue Mar 25, 2022 · 0 comments · Fixed by #805
Closed

str_flatten does not work in Redshift #804

hdplsa opened this issue Mar 25, 2022 · 0 comments · Fixed by #805

Comments

@hdplsa
Copy link
Contributor

hdplsa commented Mar 25, 2022

The str_flatten function is translated to string_agg when using the Redshift backend. The string_agg function is not supported by Redshift. Instead str_flatten should be translated into LISTAGG.

Will submit a pull request soon! :)

Please see the reprex below:

library(dbplyr)
library(DBI)
library(reprex)

con <- dbConnect(RPostgres::Redshift(), 
                 host = ,
                 dbname = , 
                 port = ,
                 user = , 
                 password = ) 

example_table <- dplyr::tribble(
  ~customer, ~day, ~item,
  "A", 1, "WATER",
  "A", 3, "BREAD",
  "A", 2, "JUICE",
  "B", 1, "APPLE",
  "B", 4, "BANANA",
  "C", 1, "MILK"
)

table_db <- dplyr::copy_to(con, example_table, temporary = T)

table_db %>%
  dplyr::group_by(customer) %>%
  dplyr::summarize(flat_string = str_flatten(item, "-"))
#> Error: Failed to prepare query: ERROR:  function string_agg(character varying, "unknown") does not exist
#> HINT:  No function matches the given name and argument types. You may need to add explicit type casts.

table_db %>%
  dplyr::group_by(customer) %>%
  dbplyr::window_order(day) %>%
  dplyr::mutate(flat_string = str_flatten(item, "-")) 
#> Error: Failed to prepare query: ERROR:  function string_agg(character varying, "unknown") does not exist
#> HINT:  No function matches the given name and argument types. You may need to add explicit type casts.

Created on 2022-03-25 by the reprex package (v2.0.0)

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.

1 participant