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
ghost opened this issue Sep 14, 2018 · 2 comments
Closed

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

ghost opened this issue Sep 14, 2018 · 2 comments
Labels
bug an unexpected problem or unintended behavior func trans 🌍 Translation of individual functions to SQL wip work in progress

Comments

@ghost
Copy link

ghost 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).*
@ghost
Copy link
Author

ghost 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?

@ghost
Copy link
Author

ghost 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.

@hadley hadley added bug an unexpected problem or unintended behavior wip work in progress func trans 🌍 Translation of individual functions to SQL labels Jan 2, 2019
@hadley hadley closed this as completed in b8d7749 Jan 2, 2019
hadley added a commit that referenced this issue Jan 9, 2019
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 wip work in progress
Projects
None yet
Development

No branches or pull requests

1 participant