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?
to your account
Brief description of the problem:
#> Expected: <SQL> substring('abcdefghijklmno', 6, 7)
#> Actual: <SQL> substring('abcdefghijklmno', 6.0, 7.0)
It looks like there was a fix here, but almost two years later, I don't seem to have it. I don't know which version the fix went into.
Maybe I have an old version?
I tried dbplyr from the vanilla tidyverse install (1.3.0), then I also tried installing dbplyr from github:
In both cases it looks like the numbers become float (numeric), and that makes Postgres (11) cranky in some other code I have:
Error in postgresqlExecStatement: RS-DBI driver: (could not Retrieve the result : ERROR: function pg_catalog.substring(text, numeric, numeric) does not exist.
The text was updated successfully, but these errors were encountered:
FYI I was trying to use this to make up rounded dates: floor_date didn't work, I tried substring(1,7)+'-01'). I ended up working around this with:
started_at = date_trunc("year", started_at))
which worked in dbplyr.
So while this is still an issue, it is not a blocker for me.
Sorry, something went wrong.
@dfrankow sorry, must've been in rush and I didn't read your issue fully — your initial description was fine.
The problem is that you're using substring() which isn't translated because it's not an R function. You want to use the R function substr():
#> <SQL> substring('abcdefghijklmno', 6.0, 7.0)
#> <SQL> SUBSTR('abcdefghijklmno', 6, 2)
Created on 2020-09-22 by the reprex package (v0.3.0.9001)
Thanks for the reply!
I don't understand "substring is not an R function". It looks like an R function to my naive eyes (see below). Maybe you mean it's not an internal function.
However, this work-around works for me. You don't have to reply.
Substring docs here.
Code saying it's in base:
function (text, first, last = 1000000L)
text <- as.character(text)
n <- max(lt <- length(text), length(first), length(last))
if (lt && lt < n)
text <- rep_len(text, length.out = n)
.Internal(substr(text, as.integer(first), as.integer(last)))
Oh shit, you're right. I got confused again because I never use substring(). I'll add it as an additional translation to all the backends.
As you like. Thanks for the tidyverse!
Sorry it took so longer to get this through my head!
I don't want you to do more work, but just so I remember: substr and substring are not quite the same.
The "last" param for substring is optional, while the "stop" param for substr is not. Since d826fbf uses the substr implementation, it may force the optional "last" to be given. Doesn't bother me.
No branches or pull requests