{"action":"created","issue":{"url":"https://api.github.com/repos/brianc/node-postgres/issues/934","repository_url":"https://api.github.com/repos/brianc/node-postgres","labels_url":"https://api.github.com/repos/brianc/node-postgres/issues/934/labels{/name}","comments_url":"https://api.github.com/repos/brianc/node-postgres/issues/934/comments","events_url":"https://api.github.com/repos/brianc/node-postgres/issues/934/events","html_url":"https://github.com/brianc/node-postgres/issues/934","id":132388103,"number":934,"title":"Column names with >1 apostrophe not escaped correctly in .query()","user":{"login":"jkgeyti","id":617033,"avatar_url":"https://avatars.githubusercontent.com/u/617033?v=3","gravatar_id":"","url":"https://api.github.com/users/jkgeyti","html_url":"https://github.com/jkgeyti","followers_url":"https://api.github.com/users/jkgeyti/followers","following_url":"https://api.github.com/users/jkgeyti/following{/other_user}","gists_url":"https://api.github.com/users/jkgeyti/gists{/gist_id}","starred_url":"https://api.github.com/users/jkgeyti/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jkgeyti/subscriptions","organizations_url":"https://api.github.com/users/jkgeyti/orgs","repos_url":"https://api.github.com/users/jkgeyti/repos","events_url":"https://api.github.com/users/jkgeyti/events{/privacy}","received_events_url":"https://api.github.com/users/jkgeyti/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-02-09T10:51:46Z","updated_at":"2016-02-10T16:29:16Z","closed_at":"2016-02-10T15:19:14Z","body":"Column names with >1 apostrophe not escaped correctly in `.query()`:\r\n\r\n```javascript\r\nvar pg = require('pg'); // version 4.4.4\r\nvar conString = \"postgres://...\";\r\n\r\n// pg.connect(conString, function(err, client, done) {  \r\n//   client.query(\"CREATE TABLE atable ( \\\"column''name\\\" TEXT )\");\r\n// });\r\n\r\npg.connect(conString, function(err, client, done) {  \r\n  client.query(\"SELECT * FROM atable\");\r\n});\r\n```\r\n\r\n```\r\n$ node bug.js\r\nundefined:4\r\nthis['column\\''name'] = rowData[0] == null ? null : parsers[0](rowData[0]);\r\n               ^^^^\r\n\r\nSyntaxError: Unexpected token ILLEGAL\r\n    at Function (native)\r\n    at Result.addFields (.../node_modules/pg/lib/result.js:98:20)\r\n    at Query.handleRowDescription (.../node_modules/pg/lib/query.js:54:16)\r\n    at null.<anonymous> (.../node_modules/pg/lib/client.js:103:24)\r\n    at emitOne (events.js:77:13)\r\n    at emit (events.js:169:7)\r\n    at Socket.<anonymous> (.../node_modules/pg/lib/connection.js:109:12)\r\n    at emitOne (events.js:77:13)\r\n    at Socket.emit (events.js:169:7)\r\n    at readableAddChunk (_stream_readable.js:146:16)\r\n```"},"comment":{"url":"https://api.github.com/repos/brianc/node-postgres/issues/comments/182462654","html_url":"https://github.com/brianc/node-postgres/issues/934#issuecomment-182462654","issue_url":"https://api.github.com/repos/brianc/node-postgres/issues/934","id":182462654,"user":{"login":"jkgeyti","id":617033,"avatar_url":"https://avatars.githubusercontent.com/u/617033?v=3","gravatar_id":"","url":"https://api.github.com/users/jkgeyti","html_url":"https://github.com/jkgeyti","followers_url":"https://api.github.com/users/jkgeyti/followers","following_url":"https://api.github.com/users/jkgeyti/following{/other_user}","gists_url":"https://api.github.com/users/jkgeyti/gists{/gist_id}","starred_url":"https://api.github.com/users/jkgeyti/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jkgeyti/subscriptions","organizations_url":"https://api.github.com/users/jkgeyti/orgs","repos_url":"https://api.github.com/users/jkgeyti/repos","events_url":"https://api.github.com/users/jkgeyti/events{/privacy}","received_events_url":"https://api.github.com/users/jkgeyti/received_events","type":"User","site_admin":false},"created_at":"2016-02-10T16:29:16Z","updated_at":"2016-02-10T16:29:16Z","body":"But the query is valid - It's a simple `SELECT * FROM table`, and column names are allowed to contain apostrophes in postgres. I don't see how a higher-level library can fix this.\r\n\r\nThe problem is that node-postgres tries to extract column names from the data returned from the database, and fails, because of the incorrect handling of column names in the (what seems to be) code generation in `addFields`."}}