{"action":"created","comment":{"url":"https://api.github.com/repos/rstats-db/RPostgres/pulls/comments/57372242","id":57372242,"diff_hunk":"@@ -59,8 +59,13 @@ setMethod(\"dbWriteTable\", c(\"PqConnection\", \"character\", \"data.frame\"),\n     }\n \n     if (!found || overwrite) {\n-      sql <- sqlCreateTable(conn, name, value, row.names = row.names,\n-        temporary = temporary)\n+      if (!missing(field.types)) {\n+        types <- structure(field.types, .Names = colnames(value))","path":"R/tables.R","position":7,"original_position":7,"commit_id":"c8bd28e47afa40ac3910b639e95a898e51e4e8b2","original_commit_id":"c8bd28e47afa40ac3910b639e95a898e51e4e8b2","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},"body":"What's the error message if the lengths are different? Do we support partial match via named list?","created_at":"2016-03-24T19:13:50Z","updated_at":"2016-03-24T19:13:50Z","html_url":"https://github.com/rstats-db/RPostgres/pull/45#discussion_r57372242","pull_request_url":"https://api.github.com/repos/rstats-db/RPostgres/pulls/45","_links":{"self":{"href":"https://api.github.com/repos/rstats-db/RPostgres/pulls/comments/57372242"},"html":{"href":"https://github.com/rstats-db/RPostgres/pull/45#discussion_r57372242"},"pull_request":{"href":"https://api.github.com/repos/rstats-db/RPostgres/pulls/45"}}},"pull_request":{"url":"https://api.github.com/repos/rstats-db/RPostgres/pulls/45","id":46300668,"html_url":"https://github.com/rstats-db/RPostgres/pull/45","diff_url":"https://github.com/rstats-db/RPostgres/pull/45.diff","patch_url":"https://github.com/rstats-db/RPostgres/pull/45.patch","issue_url":"https://api.github.com/repos/rstats-db/RPostgres/issues/45","number":45,"state":"open","locked":false,"title":"Implement field.types argument in dbWriteTable.","user":{"login":"robertzk","id":1638492,"avatar_url":"https://avatars.githubusercontent.com/u/1638492?v=3","gravatar_id":"","url":"https://api.github.com/users/robertzk","html_url":"https://github.com/robertzk","followers_url":"https://api.github.com/users/robertzk/followers","following_url":"https://api.github.com/users/robertzk/following{/other_user}","gists_url":"https://api.github.com/users/robertzk/gists{/gist_id}","starred_url":"https://api.github.com/users/robertzk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robertzk/subscriptions","organizations_url":"https://api.github.com/users/robertzk/orgs","repos_url":"https://api.github.com/users/robertzk/repos","events_url":"https://api.github.com/users/robertzk/events{/privacy}","received_events_url":"https://api.github.com/users/robertzk/received_events","type":"User","site_admin":false},"body":"@hadley This is a pretty severe issue that clobbered our local cache database.\r\n\r\nConsider the following.\r\n\r\n```r\r\niris2 <- iris[1:4, 1:4]\r\ncolnames(iris2) <- chartr(\".\", \"_\", colnames(iris2))\r\nDBI::dbWriteTable(con, \"fubar\", iris2) # Where con uses the RPostgres adapter\r\n```\r\n\r\nSince the `field.types` argument in the `dbWriteTable` method is completely unused, this creates a table with auto-inferred `real` columns.\r\n\r\n```\r\n      Table \"public.fubar\"\r\n    Column    | Type | Modifiers\r\n--------------+------+-----------\r\n Sepal_Length | real |\r\n Sepal_Width  | real |\r\n Petal_Length | real |\r\n Petal_Width  | real |\r\n```\r\n\r\nSince we deal with IDs well north of 10,000,000 in our production database, this led to a truncation wherein IDs like 35,538,288 were truncated to 35,538,200 due to precision issues. The fix would be\r\n\r\n```r\r\nDBI::dbWriteTable(con, \"fubar\", iris2, field.types = rep(\"double precision\", 4))\r\n```\r\n\r\nexcept that this argument is currently not implemented by RPostgres.\r\n\r\nI attempt to fix the issue by pre-creating a table with the correct types, as is demanded by `sqlCreateTable` when using a named character vector as the third argument. This solved our issues, and as it was a critical fix to our caching layer, I have taken the liberty of incrementing the R version. Let me know if you would like to see any further changes or remove the version update.","created_at":"2015-09-29T16:31:13Z","updated_at":"2016-03-24T19:13:50Z","closed_at":null,"merged_at":null,"merge_commit_sha":"850fb6fd4be66868a5f3734a0e14ddafb983f030","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/rstats-db/RPostgres/pulls/45/commits","review_comments_url":"https://api.github.com/repos/rstats-db/RPostgres/pulls/45/comments","review_comment_url":"https://api.github.com/repos/rstats-db/RPostgres/pulls/comments{/number}","comments_url":"https://api.github.com/repos/rstats-db/RPostgres/issues/45/comments","statuses_url":"https://api.github.com/repos/rstats-db/RPostgres/statuses/c8bd28e47afa40ac3910b639e95a898e51e4e8b2","head":{"label":"robertzk:fix_type_issues","ref":"fix_type_issues","sha":"c8bd28e47afa40ac3910b639e95a898e51e4e8b2","user":{"login":"robertzk","id":1638492,"avatar_url":"https://avatars.githubusercontent.com/u/1638492?v=3","gravatar_id":"","url":"https://api.github.com/users/robertzk","html_url":"https://github.com/robertzk","followers_url":"https://api.github.com/users/robertzk/followers","following_url":"https://api.github.com/users/robertzk/following{/other_user}","gists_url":"https://api.github.com/users/robertzk/gists{/gist_id}","starred_url":"https://api.github.com/users/robertzk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robertzk/subscriptions","organizations_url":"https://api.github.com/users/robertzk/orgs","repos_url":"https://api.github.com/users/robertzk/repos","events_url":"https://api.github.com/users/robertzk/events{/privacy}","received_events_url":"https://api.github.com/users/robertzk/received_events","type":"User","site_admin":false},"repo":{"id":43377304,"name":"RPostgres","full_name":"robertzk/RPostgres","owner":{"login":"robertzk","id":1638492,"avatar_url":"https://avatars.githubusercontent.com/u/1638492?v=3","gravatar_id":"","url":"https://api.github.com/users/robertzk","html_url":"https://github.com/robertzk","followers_url":"https://api.github.com/users/robertzk/followers","following_url":"https://api.github.com/users/robertzk/following{/other_user}","gists_url":"https://api.github.com/users/robertzk/gists{/gist_id}","starred_url":"https://api.github.com/users/robertzk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robertzk/subscriptions","organizations_url":"https://api.github.com/users/robertzk/orgs","repos_url":"https://api.github.com/users/robertzk/repos","events_url":"https://api.github.com/users/robertzk/events{/privacy}","received_events_url":"https://api.github.com/users/robertzk/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/robertzk/RPostgres","description":"A DBI-compliant interface to PostgreSQL","fork":true,"url":"https://api.github.com/repos/robertzk/RPostgres","forks_url":"https://api.github.com/repos/robertzk/RPostgres/forks","keys_url":"https://api.github.com/repos/robertzk/RPostgres/keys{/key_id}","collaborators_url":"https://api.github.com/repos/robertzk/RPostgres/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/robertzk/RPostgres/teams","hooks_url":"https://api.github.com/repos/robertzk/RPostgres/hooks","issue_events_url":"https://api.github.com/repos/robertzk/RPostgres/issues/events{/number}","events_url":"https://api.github.com/repos/robertzk/RPostgres/events","assignees_url":"https://api.github.com/repos/robertzk/RPostgres/assignees{/user}","branches_url":"https://api.github.com/repos/robertzk/RPostgres/branches{/branch}","tags_url":"https://api.github.com/repos/robertzk/RPostgres/tags","blobs_url":"https://api.github.com/repos/robertzk/RPostgres/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/robertzk/RPostgres/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/robertzk/RPostgres/git/refs{/sha}","trees_url":"https://api.github.com/repos/robertzk/RPostgres/git/trees{/sha}","statuses_url":"https://api.github.com/repos/robertzk/RPostgres/statuses/{sha}","languages_url":"https://api.github.com/repos/robertzk/RPostgres/languages","stargazers_url":"https://api.github.com/repos/robertzk/RPostgres/stargazers","contributors_url":"https://api.github.com/repos/robertzk/RPostgres/contributors","subscribers_url":"https://api.github.com/repos/robertzk/RPostgres/subscribers","subscription_url":"https://api.github.com/repos/robertzk/RPostgres/subscription","commits_url":"https://api.github.com/repos/robertzk/RPostgres/commits{/sha}","git_commits_url":"https://api.github.com/repos/robertzk/RPostgres/git/commits{/sha}","comments_url":"https://api.github.com/repos/robertzk/RPostgres/comments{/number}","issue_comment_url":"https://api.github.com/repos/robertzk/RPostgres/issues/comments{/number}","contents_url":"https://api.github.com/repos/robertzk/RPostgres/contents/{+path}","compare_url":"https://api.github.com/repos/robertzk/RPostgres/compare/{base}...{head}","merges_url":"https://api.github.com/repos/robertzk/RPostgres/merges","archive_url":"https://api.github.com/repos/robertzk/RPostgres/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/robertzk/RPostgres/downloads","issues_url":"https://api.github.com/repos/robertzk/RPostgres/issues{/number}","pulls_url":"https://api.github.com/repos/robertzk/RPostgres/pulls{/number}","milestones_url":"https://api.github.com/repos/robertzk/RPostgres/milestones{/number}","notifications_url":"https://api.github.com/repos/robertzk/RPostgres/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/robertzk/RPostgres/labels{/name}","releases_url":"https://api.github.com/repos/robertzk/RPostgres/releases{/id}","deployments_url":"https://api.github.com/repos/robertzk/RPostgres/deployments","created_at":"2015-09-29T15:45:14Z","updated_at":"2015-09-29T15:45:15Z","pushed_at":"2015-10-12T15:09:01Z","git_url":"git://github.com/robertzk/RPostgres.git","ssh_url":"git@github.com:robertzk/RPostgres.git","clone_url":"https://github.com/robertzk/RPostgres.git","svn_url":"https://github.com/robertzk/RPostgres","homepage":"","size":3131,"stargazers_count":0,"watchers_count":0,"language":"C","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"rstats-db:master","ref":"master","sha":"bd7080cc3e8c9bfc13529fc2f04aaa275087aa84","user":{"login":"rstats-db","id":5695665,"avatar_url":"https://avatars.githubusercontent.com/u/5695665?v=3","gravatar_id":"","url":"https://api.github.com/users/rstats-db","html_url":"https://github.com/rstats-db","followers_url":"https://api.github.com/users/rstats-db/followers","following_url":"https://api.github.com/users/rstats-db/following{/other_user}","gists_url":"https://api.github.com/users/rstats-db/gists{/gist_id}","starred_url":"https://api.github.com/users/rstats-db/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rstats-db/subscriptions","organizations_url":"https://api.github.com/users/rstats-db/orgs","repos_url":"https://api.github.com/users/rstats-db/repos","events_url":"https://api.github.com/users/rstats-db/events{/privacy}","received_events_url":"https://api.github.com/users/rstats-db/received_events","type":"Organization","site_admin":false},"repo":{"id":28823976,"name":"RPostgres","full_name":"rstats-db/RPostgres","owner":{"login":"rstats-db","id":5695665,"avatar_url":"https://avatars.githubusercontent.com/u/5695665?v=3","gravatar_id":"","url":"https://api.github.com/users/rstats-db","html_url":"https://github.com/rstats-db","followers_url":"https://api.github.com/users/rstats-db/followers","following_url":"https://api.github.com/users/rstats-db/following{/other_user}","gists_url":"https://api.github.com/users/rstats-db/gists{/gist_id}","starred_url":"https://api.github.com/users/rstats-db/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rstats-db/subscriptions","organizations_url":"https://api.github.com/users/rstats-db/orgs","repos_url":"https://api.github.com/users/rstats-db/repos","events_url":"https://api.github.com/users/rstats-db/events{/privacy}","received_events_url":"https://api.github.com/users/rstats-db/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/rstats-db/RPostgres","description":"A DBI-compliant interface to PostgreSQL","fork":false,"url":"https://api.github.com/repos/rstats-db/RPostgres","forks_url":"https://api.github.com/repos/rstats-db/RPostgres/forks","keys_url":"https://api.github.com/repos/rstats-db/RPostgres/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rstats-db/RPostgres/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rstats-db/RPostgres/teams","hooks_url":"https://api.github.com/repos/rstats-db/RPostgres/hooks","issue_events_url":"https://api.github.com/repos/rstats-db/RPostgres/issues/events{/number}","events_url":"https://api.github.com/repos/rstats-db/RPostgres/events","assignees_url":"https://api.github.com/repos/rstats-db/RPostgres/assignees{/user}","branches_url":"https://api.github.com/repos/rstats-db/RPostgres/branches{/branch}","tags_url":"https://api.github.com/repos/rstats-db/RPostgres/tags","blobs_url":"https://api.github.com/repos/rstats-db/RPostgres/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rstats-db/RPostgres/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rstats-db/RPostgres/git/refs{/sha}","trees_url":"https://api.github.com/repos/rstats-db/RPostgres/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rstats-db/RPostgres/statuses/{sha}","languages_url":"https://api.github.com/repos/rstats-db/RPostgres/languages","stargazers_url":"https://api.github.com/repos/rstats-db/RPostgres/stargazers","contributors_url":"https://api.github.com/repos/rstats-db/RPostgres/contributors","subscribers_url":"https://api.github.com/repos/rstats-db/RPostgres/subscribers","subscription_url":"https://api.github.com/repos/rstats-db/RPostgres/subscription","commits_url":"https://api.github.com/repos/rstats-db/RPostgres/commits{/sha}","git_commits_url":"https://api.github.com/repos/rstats-db/RPostgres/git/commits{/sha}","comments_url":"https://api.github.com/repos/rstats-db/RPostgres/comments{/number}","issue_comment_url":"https://api.github.com/repos/rstats-db/RPostgres/issues/comments{/number}","contents_url":"https://api.github.com/repos/rstats-db/RPostgres/contents/{+path}","compare_url":"https://api.github.com/repos/rstats-db/RPostgres/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rstats-db/RPostgres/merges","archive_url":"https://api.github.com/repos/rstats-db/RPostgres/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rstats-db/RPostgres/downloads","issues_url":"https://api.github.com/repos/rstats-db/RPostgres/issues{/number}","pulls_url":"https://api.github.com/repos/rstats-db/RPostgres/pulls{/number}","milestones_url":"https://api.github.com/repos/rstats-db/RPostgres/milestones{/number}","notifications_url":"https://api.github.com/repos/rstats-db/RPostgres/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rstats-db/RPostgres/labels{/name}","releases_url":"https://api.github.com/repos/rstats-db/RPostgres/releases{/id}","deployments_url":"https://api.github.com/repos/rstats-db/RPostgres/deployments","created_at":"2015-01-05T17:43:02Z","updated_at":"2016-02-10T19:04:05Z","pushed_at":"2016-03-24T18:43:09Z","git_url":"git://github.com/rstats-db/RPostgres.git","ssh_url":"git@github.com:rstats-db/RPostgres.git","clone_url":"https://github.com/rstats-db/RPostgres.git","svn_url":"https://github.com/rstats-db/RPostgres","homepage":"","size":3059,"stargazers_count":43,"watchers_count":43,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":16,"mirror_url":null,"open_issues_count":39,"forks":16,"open_issues":39,"watchers":43,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rstats-db/RPostgres/pulls/45"},"html":{"href":"https://github.com/rstats-db/RPostgres/pull/45"},"issue":{"href":"https://api.github.com/repos/rstats-db/RPostgres/issues/45"},"comments":{"href":"https://api.github.com/repos/rstats-db/RPostgres/issues/45/comments"},"review_comments":{"href":"https://api.github.com/repos/rstats-db/RPostgres/pulls/45/comments"},"review_comment":{"href":"https://api.github.com/repos/rstats-db/RPostgres/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/rstats-db/RPostgres/pulls/45/commits"},"statuses":{"href":"https://api.github.com/repos/rstats-db/RPostgres/statuses/c8bd28e47afa40ac3910b639e95a898e51e4e8b2"}}}}