{"action":"created","issue":{"url":"https://api.github.com/repos/tidyverse/dplyr/issues/3389","repository_url":"https://api.github.com/repos/tidyverse/dplyr","labels_url":"https://api.github.com/repos/tidyverse/dplyr/issues/3389/labels{/name}","comments_url":"https://api.github.com/repos/tidyverse/dplyr/issues/3389/comments","events_url":"https://api.github.com/repos/tidyverse/dplyr/issues/3389/events","html_url":"https://github.com/tidyverse/dplyr/issues/3389","id":301815527,"number":3389,"title":"Postgres table creation not behaving like RPostgreSQL ","user":{"login":"mwillumz","id":371760,"avatar_url":"https://avatars0.githubusercontent.com/u/371760?v=4","gravatar_id":"","url":"https://api.github.com/users/mwillumz","html_url":"https://github.com/mwillumz","followers_url":"https://api.github.com/users/mwillumz/followers","following_url":"https://api.github.com/users/mwillumz/following{/other_user}","gists_url":"https://api.github.com/users/mwillumz/gists{/gist_id}","starred_url":"https://api.github.com/users/mwillumz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mwillumz/subscriptions","organizations_url":"https://api.github.com/users/mwillumz/orgs","repos_url":"https://api.github.com/users/mwillumz/repos","events_url":"https://api.github.com/users/mwillumz/events{/privacy}","received_events_url":"https://api.github.com/users/mwillumz/received_events","type":"User","site_admin":false},"labels":[{"id":213548409,"url":"https://api.github.com/repos/tidyverse/dplyr/labels/database","name":"database","color":"eeeeee","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-03-02T16:01:21Z","updated_at":"2018-03-19T14:29:42Z","closed_at":null,"author_association":"NONE","body":"I need to modify the postgres connection ever so slightly to avoid a warning and undesired behavior in a greenplum database. If I don't provide a \"distributed by\" clause upon table creation the data is loaded according to the first column of the data provided. \r\n\r\nWith PostgreSQL I am able to accomplish this with the first code chunk below. However, the corresponding approach does not work with the PqConnection \r\nclass from RPostgres.\r\n\r\nRPostgreSQL (works as expected and distributes randomly):\r\n\r\n```r\r\n#' @importFrom assertthat assert_that\r\n#' @importFrom rlang is_string\r\n#' @importFrom dbplyr build_sql as.sql\r\n#' @export\r\ndb_create_table.PostgreSQLConnection <- function(con, table, types, temporary = TRUE, ...) {\r\n  assertthat::assert_that(rlang::is_string(table), is.character(types))\r\n\r\n  field_names <- escape(ident(names(types)), collapse = NULL, con = con)\r\n  fields <- sql_vector(\r\n    paste0(field_names, \" \", types),\r\n    parens = TRUE,\r\n    collapse = \", \",\r\n    con = con\r\n  )\r\n  sql <- dbplyr::build_sql(\r\n    \"CREATE \", if (temporary) sql(\"TEMPORARY \"),\r\n    \"TABLE \", dbplyr::as.sql(table), \" \", fields,\r\n    \" DISTRIBUTED RANDOMLY\",\r\n    con = con\r\n  )\r\n\r\n  DBI::dbExecute(con, sql)\r\n}\r\n```\r\nRPostgres(not implemented... so uses first column for distribution as per db default):\r\n\r\n```r\r\n#' @importFrom assertthat assert_that\r\n#' @importFrom rlang is_string\r\n#' @importFrom dbplyr build_sql as.sql\r\n#' @export\r\ndb_create_table.PqConnection <- function(con, table, types, temporary = TRUE, ...) {\r\n  assertthat::assert_that(rlang::is_string(table), is.character(types))\r\n\r\n  field_names <- escape(ident(names(types)), collapse = NULL, con = con)\r\n  fields <- sql_vector(\r\n    paste0(field_names, \" \", types),\r\n    parens = TRUE,\r\n    collapse = \", \",\r\n    con = con\r\n  )\r\n  sql <- dbplyr::build_sql(\r\n    \"CREATE \", if (temporary) sql(\"TEMPORARY \"),\r\n    \"TABLE \", dbplyr::as.sql(table), \" \", fields,\r\n    \" DISTRIBUTED RANDOMLY\",\r\n    con = con\r\n  )\r\n\r\n  DBI::dbExecute(con, sql)\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/tidyverse/dplyr/issues/comments/374231687","html_url":"https://github.com/tidyverse/dplyr/issues/3389#issuecomment-374231687","issue_url":"https://api.github.com/repos/tidyverse/dplyr/issues/3389","id":374231687,"user":{"login":"edgararuiz","id":7875923,"avatar_url":"https://avatars1.githubusercontent.com/u/7875923?v=4","gravatar_id":"","url":"https://api.github.com/users/edgararuiz","html_url":"https://github.com/edgararuiz","followers_url":"https://api.github.com/users/edgararuiz/followers","following_url":"https://api.github.com/users/edgararuiz/following{/other_user}","gists_url":"https://api.github.com/users/edgararuiz/gists{/gist_id}","starred_url":"https://api.github.com/users/edgararuiz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edgararuiz/subscriptions","organizations_url":"https://api.github.com/users/edgararuiz/orgs","repos_url":"https://api.github.com/users/edgararuiz/repos","events_url":"https://api.github.com/users/edgararuiz/events{/privacy}","received_events_url":"https://api.github.com/users/edgararuiz/received_events","type":"User","site_admin":false},"created_at":"2018-03-19T14:29:42Z","updated_at":"2018-03-19T14:29:42Z","author_association":"NONE","body":"Hi @mwillumz , would you like to submit a Pull Request for this change?  That way you can get credit for your work.  I'll be happy to help you with it."}}
{"actor":{"display_login":"edgararuiz"}}