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

filter in can not take empty vector of values on PostgreSQL #160

Closed
move bot opened this issue Sep 14, 2018 · 2 comments
Closed

filter in can not take empty vector of values on PostgreSQL #160

move bot opened this issue Sep 14, 2018 · 2 comments

Comments

@move
Copy link

@move move bot commented Sep 14, 2018

@JohnMount commented on Feb 22, 2018, 3:59 PM UTC:

filter %in% c() throws on PostgreSQL.

``` r library("dplyr")
## 
## Attaching package: 'dplyr'

## The following objects are masked from 'package:stats':
## 
##     filter, lag

## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union

db <- DBI::dbConnect(RPostgreSQL::PostgreSQL(),
host = 'localhost',
port = 5432,
user = 'johnmount',
password = '')
table <- dplyr::copy_to(db,
data.frame(idx = 1:5))

works

vals <- c(1, 2)
table %>% filter(idx %in% vals)

## # Source:   lazy query [?? x 1]
## # Database: postgres 10.0.2 [johnmount@localhost:5432/johnmount]
##     idx
##   <int>
## 1     1
## 2     2

throws

vals <- c()
table %>% filter(idx %in% vals)

## Error in postgresqlExecStatement(conn, statement, ...): RS-DBI driver: (could not Retrieve the result : ERROR:  syntax error at or near ")"
## LINE 3: WHERE ("idx" IN ())
##                          ^
## )

DBI::dbDisconnect(db)

## [1] TRUE

</details>

```</details>

*This issue was moved by [romainfrancois](https://github.com/romainfrancois) from [tidyverse/dplyr#3375](https://github.com/tidyverse/dplyr/issues/3375).*
@move
Copy link
Author

@move move bot commented Sep 14, 2018

@hadley commented on May 20, 2018, 2:15 PM UTC:

Minimal reprex:

library(dplyr, warn.conflicts = FALSE)

lf1 <- dbplyr::lazy_frame(x = 1:5, src = dbplyr::simulate_dbi())
lf1 %>% 
  filter(x %in% c()) %>%
  show_query()
#> <SQL> SELECT *
#> FROM "df"
#> WHERE ("x" IN ())

I'm not sure if there's anything we can do here. I guess we could translate x %in% c() to FALSE?

@move
Copy link
Author

@move move bot commented Sep 14, 2018

@mgirlich commented on May 21, 2018, 5:41 AM UTC:

@hadley it would make sense imho and be the same behaviour as for local dataframes. I already did a PR for this behaviour.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant