{"action":"created","comment":{"url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/pulls/comments/191726804","pull_request_review_id":124352266,"id":191726804,"diff_hunk":"@@ -61,8 +61,9 @@ module.exports = {\n                 })\n                 .on('close', () => {\n                     if (!requestEnded) {\n+                        const connection = client.connection;\n+                        connection.sendCopyFail();","path":"app/services/stream_copy.js","position":null,"original_position":5,"commit_id":"310f652ae418454d52bb88a16235aaf00bf95399","original_commit_id":"310f652ae418454d52bb88a16235aaf00bf95399","user":{"login":"rafatower","id":1914276,"avatar_url":"https://avatars1.githubusercontent.com/u/1914276?v=4","gravatar_id":"","url":"https://api.github.com/users/rafatower","html_url":"https://github.com/rafatower","followers_url":"https://api.github.com/users/rafatower/followers","following_url":"https://api.github.com/users/rafatower/following{/other_user}","gists_url":"https://api.github.com/users/rafatower/gists{/gist_id}","starred_url":"https://api.github.com/users/rafatower/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rafatower/subscriptions","organizations_url":"https://api.github.com/users/rafatower/orgs","repos_url":"https://api.github.com/users/rafatower/repos","events_url":"https://api.github.com/users/rafatower/events{/privacy}","received_events_url":"https://api.github.com/users/rafatower/received_events","type":"User","site_admin":false},"body":":clap: :clap: :clap: :clap: ","created_at":"2018-05-30T11:08:28Z","updated_at":"2018-05-30T11:08:28Z","html_url":"https://github.com/CartoDB/CartoDB-SQL-API/pull/480#discussion_r191726804","pull_request_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/pulls/480","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/pulls/comments/191726804"},"html":{"href":"https://github.com/CartoDB/CartoDB-SQL-API/pull/480#discussion_r191726804"},"pull_request":{"href":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/pulls/480"}}},"pull_request":{"url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/pulls/480","id":184253731,"html_url":"https://github.com/CartoDB/CartoDB-SQL-API/pull/480","diff_url":"https://github.com/CartoDB/CartoDB-SQL-API/pull/480.diff","patch_url":"https://github.com/CartoDB/CartoDB-SQL-API/pull/480.patch","issue_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/issues/480","number":480,"state":"open","locked":false,"title":"/copyfrom and /copyto end points","user":{"login":"pramsey","id":113883,"avatar_url":"https://avatars3.githubusercontent.com/u/113883?v=4","gravatar_id":"","url":"https://api.github.com/users/pramsey","html_url":"https://github.com/pramsey","followers_url":"https://api.github.com/users/pramsey/followers","following_url":"https://api.github.com/users/pramsey/following{/other_user}","gists_url":"https://api.github.com/users/pramsey/gists{/gist_id}","starred_url":"https://api.github.com/users/pramsey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pramsey/subscriptions","organizations_url":"https://api.github.com/users/pramsey/orgs","repos_url":"https://api.github.com/users/pramsey/repos","events_url":"https://api.github.com/users/pramsey/events{/privacy}","received_events_url":"https://api.github.com/users/pramsey/received_events","type":"User","site_admin":false},"body":"**NOTE: Still a work-in-progress, PR created for purposes of review and feedback.**\r\n\r\nAdds support for streaming data in/out of the database using the `COPY` command and new end points.\r\n\r\n### `/copyfrom`\r\n\r\nReads a file POST'ed to the end point and streams the contents into a PostgreSQL [COPY ... FROM](https://www.postgresql.org/docs/current/static/sql-copy.html).\r\n\r\n* POST to `/copyfrom` only\r\n* `q` parameter contains the [COPY](https://www.postgresql.org/docs/current/static/sql-copy.html) command, in the URL \r\n* POST body mime-type `application/octet-stream`\r\n* POST body contains the COPY file, in the format described by the COPY command\r\n* Example: \r\n  ```curl -X POST -H \"Content-Encoding: gzip\" -H \"Transfer-Encoding: chunked\" -H \"Content-Type: application/octet-stream\" --data-binary @upload_example.csv.gz \"http://cdb.localhost.lan:8080/api/v2/sql/copyfrom?api_key={api_key}&q=COPY+upload_example+(the_geom,+name,+age)+FROM+STDIN+WITH+(FORMAT+csv,+HEADER+true)\"```\r\n* Returns: `{\"time\":0.061, \"total_rows\":3}`\r\n\r\n### `/copyto`\r\n\r\nRuns a PostgreSQL [COPY ... TO](https://www.postgresql.org/docs/current/static/sql-copy.html) and streams the result to the caller as an `application/octet-stream` download.\r\n\r\n* GET from `/copyto` only\r\n* response mime-type `application/octet-stream`\r\n* `filename` parameter contains the desired file name for the `Content-disposition` header\r\n* `sql` parameter contains the `COPY ... TO` command to run\r\n* example: `curl \"http://cdb.localhost.lan:8080/api/v2/copyto?sql=copy+foo+to+stdout&filename=output.dmp\"`\r\n","created_at":"2018-04-26T07:51:37Z","updated_at":"2018-05-30T11:08:28Z","closed_at":null,"merged_at":null,"merge_commit_sha":"25e3414b729ee1413df84e80ff352c72fbb9a203","assignee":null,"assignees":[],"requested_reviewers":[{"login":"enekid","id":623492,"avatar_url":"https://avatars2.githubusercontent.com/u/623492?v=4","gravatar_id":"","url":"https://api.github.com/users/enekid","html_url":"https://github.com/enekid","followers_url":"https://api.github.com/users/enekid/followers","following_url":"https://api.github.com/users/enekid/following{/other_user}","gists_url":"https://api.github.com/users/enekid/gists{/gist_id}","starred_url":"https://api.github.com/users/enekid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/enekid/subscriptions","organizations_url":"https://api.github.com/users/enekid/orgs","repos_url":"https://api.github.com/users/enekid/repos","events_url":"https://api.github.com/users/enekid/events{/privacy}","received_events_url":"https://api.github.com/users/enekid/received_events","type":"User","site_admin":false},{"login":"dgaubert","id":1936888,"avatar_url":"https://avatars0.githubusercontent.com/u/1936888?v=4","gravatar_id":"","url":"https://api.github.com/users/dgaubert","html_url":"https://github.com/dgaubert","followers_url":"https://api.github.com/users/dgaubert/followers","following_url":"https://api.github.com/users/dgaubert/following{/other_user}","gists_url":"https://api.github.com/users/dgaubert/gists{/gist_id}","starred_url":"https://api.github.com/users/dgaubert/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dgaubert/subscriptions","organizations_url":"https://api.github.com/users/dgaubert/orgs","repos_url":"https://api.github.com/users/dgaubert/repos","events_url":"https://api.github.com/users/dgaubert/events{/privacy}","received_events_url":"https://api.github.com/users/dgaubert/received_events","type":"User","site_admin":false}],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/pulls/480/commits","review_comments_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/pulls/480/comments","review_comment_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/pulls/comments{/number}","comments_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/issues/480/comments","statuses_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/statuses/310f652ae418454d52bb88a16235aaf00bf95399","head":{"label":"CartoDB:pgcopy-stream","ref":"pgcopy-stream","sha":"310f652ae418454d52bb88a16235aaf00bf95399","user":{"login":"CartoDB","id":1799254,"avatar_url":"https://avatars0.githubusercontent.com/u/1799254?v=4","gravatar_id":"","url":"https://api.github.com/users/CartoDB","html_url":"https://github.com/CartoDB","followers_url":"https://api.github.com/users/CartoDB/followers","following_url":"https://api.github.com/users/CartoDB/following{/other_user}","gists_url":"https://api.github.com/users/CartoDB/gists{/gist_id}","starred_url":"https://api.github.com/users/CartoDB/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CartoDB/subscriptions","organizations_url":"https://api.github.com/users/CartoDB/orgs","repos_url":"https://api.github.com/users/CartoDB/repos","events_url":"https://api.github.com/users/CartoDB/events{/privacy}","received_events_url":"https://api.github.com/users/CartoDB/received_events","type":"Organization","site_admin":false},"repo":{"id":1994634,"name":"CartoDB-SQL-API","full_name":"CartoDB/CartoDB-SQL-API","owner":{"login":"CartoDB","id":1799254,"avatar_url":"https://avatars0.githubusercontent.com/u/1799254?v=4","gravatar_id":"","url":"https://api.github.com/users/CartoDB","html_url":"https://github.com/CartoDB","followers_url":"https://api.github.com/users/CartoDB/followers","following_url":"https://api.github.com/users/CartoDB/following{/other_user}","gists_url":"https://api.github.com/users/CartoDB/gists{/gist_id}","starred_url":"https://api.github.com/users/CartoDB/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CartoDB/subscriptions","organizations_url":"https://api.github.com/users/CartoDB/orgs","repos_url":"https://api.github.com/users/CartoDB/repos","events_url":"https://api.github.com/users/CartoDB/events{/privacy}","received_events_url":"https://api.github.com/users/CartoDB/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/CartoDB/CartoDB-SQL-API","description":"CartoDB SQL API","fork":false,"url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API","forks_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/forks","keys_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/keys{/key_id}","collaborators_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/teams","hooks_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/hooks","issue_events_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/issues/events{/number}","events_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/events","assignees_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/assignees{/user}","branches_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/branches{/branch}","tags_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/tags","blobs_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/git/refs{/sha}","trees_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/git/trees{/sha}","statuses_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/statuses/{sha}","languages_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/languages","stargazers_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/stargazers","contributors_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/contributors","subscribers_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/subscribers","subscription_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/subscription","commits_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/commits{/sha}","git_commits_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/git/commits{/sha}","comments_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/comments{/number}","issue_comment_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/issues/comments{/number}","contents_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/contents/{+path}","compare_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/compare/{base}...{head}","merges_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/merges","archive_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/downloads","issues_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/issues{/number}","pulls_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/pulls{/number}","milestones_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/milestones{/number}","notifications_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/labels{/name}","releases_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/releases{/id}","deployments_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/deployments","created_at":"2011-07-04T09:35:13Z","updated_at":"2018-05-17T09:34:13Z","pushed_at":"2018-05-30T11:05:47Z","git_url":"git://github.com/CartoDB/CartoDB-SQL-API.git","ssh_url":"git@github.com:CartoDB/CartoDB-SQL-API.git","clone_url":"https://github.com/CartoDB/CartoDB-SQL-API.git","svn_url":"https://github.com/CartoDB/CartoDB-SQL-API","homepage":"","size":6986,"stargazers_count":42,"watchers_count":42,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":52,"mirror_url":null,"archived":false,"open_issues_count":74,"license":{"key":"bsd-3-clause","name":"BSD 3-Clause \"New\" or \"Revised\" License","spdx_id":"BSD-3-Clause","url":"https://api.github.com/licenses/bsd-3-clause"},"forks":52,"open_issues":74,"watchers":42,"default_branch":"master"}},"base":{"label":"CartoDB:master","ref":"master","sha":"9912dbebad7aed6c3f346538b653ecd049ecf3b4","user":{"login":"CartoDB","id":1799254,"avatar_url":"https://avatars0.githubusercontent.com/u/1799254?v=4","gravatar_id":"","url":"https://api.github.com/users/CartoDB","html_url":"https://github.com/CartoDB","followers_url":"https://api.github.com/users/CartoDB/followers","following_url":"https://api.github.com/users/CartoDB/following{/other_user}","gists_url":"https://api.github.com/users/CartoDB/gists{/gist_id}","starred_url":"https://api.github.com/users/CartoDB/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CartoDB/subscriptions","organizations_url":"https://api.github.com/users/CartoDB/orgs","repos_url":"https://api.github.com/users/CartoDB/repos","events_url":"https://api.github.com/users/CartoDB/events{/privacy}","received_events_url":"https://api.github.com/users/CartoDB/received_events","type":"Organization","site_admin":false},"repo":{"id":1994634,"name":"CartoDB-SQL-API","full_name":"CartoDB/CartoDB-SQL-API","owner":{"login":"CartoDB","id":1799254,"avatar_url":"https://avatars0.githubusercontent.com/u/1799254?v=4","gravatar_id":"","url":"https://api.github.com/users/CartoDB","html_url":"https://github.com/CartoDB","followers_url":"https://api.github.com/users/CartoDB/followers","following_url":"https://api.github.com/users/CartoDB/following{/other_user}","gists_url":"https://api.github.com/users/CartoDB/gists{/gist_id}","starred_url":"https://api.github.com/users/CartoDB/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CartoDB/subscriptions","organizations_url":"https://api.github.com/users/CartoDB/orgs","repos_url":"https://api.github.com/users/CartoDB/repos","events_url":"https://api.github.com/users/CartoDB/events{/privacy}","received_events_url":"https://api.github.com/users/CartoDB/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/CartoDB/CartoDB-SQL-API","description":"CartoDB SQL API","fork":false,"url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API","forks_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/forks","keys_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/keys{/key_id}","collaborators_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/teams","hooks_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/hooks","issue_events_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/issues/events{/number}","events_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/events","assignees_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/assignees{/user}","branches_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/branches{/branch}","tags_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/tags","blobs_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/git/refs{/sha}","trees_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/git/trees{/sha}","statuses_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/statuses/{sha}","languages_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/languages","stargazers_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/stargazers","contributors_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/contributors","subscribers_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/subscribers","subscription_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/subscription","commits_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/commits{/sha}","git_commits_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/git/commits{/sha}","comments_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/comments{/number}","issue_comment_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/issues/comments{/number}","contents_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/contents/{+path}","compare_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/compare/{base}...{head}","merges_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/merges","archive_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/downloads","issues_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/issues{/number}","pulls_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/pulls{/number}","milestones_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/milestones{/number}","notifications_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/labels{/name}","releases_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/releases{/id}","deployments_url":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/deployments","created_at":"2011-07-04T09:35:13Z","updated_at":"2018-05-17T09:34:13Z","pushed_at":"2018-05-30T11:05:47Z","git_url":"git://github.com/CartoDB/CartoDB-SQL-API.git","ssh_url":"git@github.com:CartoDB/CartoDB-SQL-API.git","clone_url":"https://github.com/CartoDB/CartoDB-SQL-API.git","svn_url":"https://github.com/CartoDB/CartoDB-SQL-API","homepage":"","size":6986,"stargazers_count":42,"watchers_count":42,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":52,"mirror_url":null,"archived":false,"open_issues_count":74,"license":{"key":"bsd-3-clause","name":"BSD 3-Clause \"New\" or \"Revised\" License","spdx_id":"BSD-3-Clause","url":"https://api.github.com/licenses/bsd-3-clause"},"forks":52,"open_issues":74,"watchers":42,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/pulls/480"},"html":{"href":"https://github.com/CartoDB/CartoDB-SQL-API/pull/480"},"issue":{"href":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/issues/480"},"comments":{"href":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/issues/480/comments"},"review_comments":{"href":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/pulls/480/comments"},"review_comment":{"href":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/pulls/480/commits"},"statuses":{"href":"https://api.github.com/repos/CartoDB/CartoDB-SQL-API/statuses/310f652ae418454d52bb88a16235aaf00bf95399"}},"author_association":"NONE"}}
{"actor":{"display_login":"rafatower"}}