{"action":"closed","issue":{"url":"https://api.github.com/repos/hadley/dplyr/issues/982","labels_url":"https://api.github.com/repos/hadley/dplyr/issues/982/labels{/name}","comments_url":"https://api.github.com/repos/hadley/dplyr/issues/982/comments","events_url":"https://api.github.com/repos/hadley/dplyr/issues/982/events","html_url":"https://github.com/hadley/dplyr/issues/982","id":58040933,"number":982,"title":"SQL translation of \"x %in% 1\" fails","user":{"login":"zozlak","id":6503177,"avatar_url":"https://avatars.githubusercontent.com/u/6503177?v=3","gravatar_id":"","url":"https://api.github.com/users/zozlak","html_url":"https://github.com/zozlak","followers_url":"https://api.github.com/users/zozlak/followers","following_url":"https://api.github.com/users/zozlak/following{/other_user}","gists_url":"https://api.github.com/users/zozlak/gists{/gist_id}","starred_url":"https://api.github.com/users/zozlak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zozlak/subscriptions","organizations_url":"https://api.github.com/users/zozlak/orgs","repos_url":"https://api.github.com/users/zozlak/repos","events_url":"https://api.github.com/users/zozlak/events{/privacy}","received_events_url":"https://api.github.com/users/zozlak/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-02-18T08:44:06Z","updated_at":"2015-05-19T16:20:35Z","closed_at":"2015-05-19T16:20:35Z","body":"`sql_translate(x %in% 1)` is `x IN 1`, which is a not valid SQL syntax.\r\nIn fact every SQL infix operator which takes a vector of values on the right side and is passed a vector of length 1 is affected by this issue.\r\n\r\nThis can be solved by changing dplyr::sql_vector() defaults to add parens regarding the length of a vector.\r\n\r\nIn cases when parens are not needed, this should not break anything (adding parens around single values is valid in SQL, e.g. `(1.0) + (2.0)` is valid) and it will assure that infix operators taking vector on the right side will be properly translated into SQL.\r\n\r\nI also reccomend to add a test to test-translate-sql:\r\n```r\r\nout <- translate_sql(x %in% 1)\r\nexpect_equal(out, sql('\"x\" IN (1.0)'))\r\nout <- translate_sql(x %in% 1:2)\r\nexpect_equal(out, sql('\"x\" IN (1.0, 2.0)'))\r\n```\r\n\r\nI can prepare a patch but wanted to discuss it before."}}