You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, since this is my first time ever posting a github issue I spoke with @edgararuiz to get sign off before posting, apologies if I did not follow best practices!
A co-worker and I found a translation issue when working with Amazon Redshift for stringr::str_sub(). The SQL translation is to SUBSTR, which is an unsupported Redshift function. Instead, the translation ought to be to SUBSTRING, which is supported.
Error: <SQL> 'SELECT "catid", "catgroup", "catname", "catdesc", SUBSTR("catgroup", 1, 5) AS "catgroup_sub_string"
FROM "category_stage"
LIMIT 11'
nanodbc/nanodbc.cpp:1587: XX000: [Amazon][Amazon Redshift] (30) Error occurred while trying to execute a query: [SQLState XX000] ERROR: SUBSTR() function is not supported (Hint: use SUBSTRING instead)
DETAIL:
-----------------------------------------------
error: SUBSTR() function is not supported (Hint: use SUBSTRING instead)
code: 8001
context:
query: 4141058
location: cg_expr.cpp:1970
process: padbmaster [pid=14742]
-----------------------------------------------
str_sub & SUBSTRING comparison
Further, L is required when using the supported SUBSTRING in a mutate statement and the arguments are the index of the string you wish to start at and the number of characters after the start. This is different than stringr::str_sub():
Error: <SQL> 'SELECT "catid", "catgroup", "catname", "catdesc", SUBSTRING("catgroup", 3.0, 2.0) AS "catgroup_sub_string"
FROM "category_stage"
LIMIT 11'
nanodbc/nanodbc.cpp:1587: XX000: [Amazon][Amazon Redshift] (30) Error occurred while trying to execute a query: [SQLState XX000] ERROR: Not implemented
DETAIL:
-----------------------------------------------
error: Not implemented
code: 1001
context: 'false' - Use of complex SQL function substring() is not supported
query: 4141142
location: cg_expr.cpp:309
process: padbmaster [pid=14742]
-----------------------------------------------
Hopefully this was helpful!
The text was updated successfully, but these errors were encountered:
samstiyer
changed the title
Redshift Incorrect SQL Translation for stringr::sub_string
Redshift Incorrect SQL Translation for stringr::str_sub
Jun 22, 2019
This appears to be valid postgres code, but isn't valid for redshift. Currently redshift uses exactly the same translations as postgres, so we'd have to add a custom redshift translations before we could fix that. To make that easier could you please give me the result of class(redshift_connection)?
Another thing here -- if its possible to check which of the substr and substring functions are available and use one that's available during translation, that would be helpful for avoiding errors. For whatever reason, the instance of redshift I'm connected to, only supports one of them, which can be a gotcha.
Hi, since this is my first time ever posting a github issue I spoke with @edgararuiz to get sign off before posting, apologies if I did not follow best practices!
A co-worker and I found a translation issue when working with Amazon Redshift for
stringr::str_sub()
. The SQL translation is toSUBSTR
, which is an unsupported Redshift function. Instead, the translation ought to be toSUBSTRING
, which is supported.Example
Table
stringr::str_sub
-show_query()
exampleResult
stringr::str_sub
Executing QueryResult
str_sub
&SUBSTRING
comparisonFurther,
L
is required when using the supportedSUBSTRING
in a mutate statement and the arguments are the index of the string you wish to start at and the number of characters after the start. This is different thanstringr::str_sub()
:stringr::str_sub(string, start, end)
SUBSTRING(string, start, numberofcharacters)
stringr::str_sub()
Result
SUBSTRING
Result
Example of not using
L
inSUBSTRING
Hopefully this was helpful!
The text was updated successfully, but these errors were encountered: