{"action":"created","issue":{"url":"https://api.github.com/repos/hadley/dplyr/issues/1503","labels_url":"https://api.github.com/repos/hadley/dplyr/issues/1503/labels{/name}","comments_url":"https://api.github.com/repos/hadley/dplyr/issues/1503/comments","events_url":"https://api.github.com/repos/hadley/dplyr/issues/1503/events","html_url":"https://github.com/hadley/dplyr/issues/1503","id":114879966,"number":1503,"title":"mutate_tbl.sql doesn't support in-place renaming","user":{"login":"jarodmeng","id":854353,"avatar_url":"https://avatars.githubusercontent.com/u/854353?v=3","gravatar_id":"","url":"https://api.github.com/users/jarodmeng","html_url":"https://github.com/jarodmeng","followers_url":"https://api.github.com/users/jarodmeng/followers","following_url":"https://api.github.com/users/jarodmeng/following{/other_user}","gists_url":"https://api.github.com/users/jarodmeng/gists{/gist_id}","starred_url":"https://api.github.com/users/jarodmeng/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jarodmeng/subscriptions","organizations_url":"https://api.github.com/users/jarodmeng/orgs","repos_url":"https://api.github.com/users/jarodmeng/repos","events_url":"https://api.github.com/users/jarodmeng/events{/privacy}","received_events_url":"https://api.github.com/users/jarodmeng/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":15,"created_at":"2015-11-03T18:28:17Z","updated_at":"2015-11-05T08:11:55Z","closed_at":"2015-11-03T23:19:06Z","body":"mutate_.tbl_sql combines new input with all previous select ([here](https://github.com/hadley/dplyr/blob/dd10ccd543a2bea99573e6622b46d50f657b0c1f/R/tbl-sql.r#L339)). If any input element has the same name as any original column, it will result in duplicated column name error in SQL.\r\n\r\nThis behavior is also different from mutate_.tbl_df."},"comment":{"url":"https://api.github.com/repos/hadley/dplyr/issues/comments/153983590","html_url":"https://github.com/hadley/dplyr/issues/1503#issuecomment-153983590","issue_url":"https://api.github.com/repos/hadley/dplyr/issues/1503","id":153983590,"user":{"login":"krlmlr","id":1741643,"avatar_url":"https://avatars.githubusercontent.com/u/1741643?v=3","gravatar_id":"","url":"https://api.github.com/users/krlmlr","html_url":"https://github.com/krlmlr","followers_url":"https://api.github.com/users/krlmlr/followers","following_url":"https://api.github.com/users/krlmlr/following{/other_user}","gists_url":"https://api.github.com/users/krlmlr/gists{/gist_id}","starred_url":"https://api.github.com/users/krlmlr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/krlmlr/subscriptions","organizations_url":"https://api.github.com/users/krlmlr/orgs","repos_url":"https://api.github.com/users/krlmlr/repos","events_url":"https://api.github.com/users/krlmlr/events{/privacy}","received_events_url":"https://api.github.com/users/krlmlr/received_events","type":"User","site_admin":false},"created_at":"2015-11-05T08:11:55Z","updated_at":"2015-11-05T08:11:55Z","body":"@jarodmeng: There's no doubt that the current implementation behaves in unexpected ways. And, of course, my queries were sloppy. I believe the following translation of `remote_iris %>% mutate(Petal.Width = Petal.Width * 10L)` is correct:\r\n\r\n```\r\nSELECT Sepal.Length, Sepal.Width, Petal.Length, Petal.Width * 10 AS Petal.Width, Species FROM (SELECT * FROM iris) iris1\r\n```\r\n\r\nI also agree that the following is correct as well:\r\n\r\n```\r\nSELECT Sepal.Length, Sepal.Width, Petal.Length, Petal.Width * 10 AS Petal.Width, Species FROM iris\r\n```\r\n\r\nSubqueries help in more complicated cases like the following:\r\n\r\n```\r\nremote_iris %>% mutate(Petal.Width = Petal.Width + 2, Petal.Width = Petal.Width * Petal.Width)\r\n```\r\n\r\nBTW, this problem is also mentioned in #1423.\r\n\r\nsrdb is a public database with published credentials."}}