From f9dc8c82b63c32194f95d84ebc4e057e69ac13d3 Mon Sep 17 00:00:00 2001 From: Charmander <~@charmander.me> Date: Thu, 31 May 2018 22:19:44 +0000 Subject: [PATCH] Count columns correctly even when the result set is empty --- FAQ.md | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/FAQ.md b/FAQ.md index 47f9f05..bf55931 100644 --- a/FAQ.md +++ b/FAQ.md @@ -36,15 +36,8 @@ client.query(..., function(err, result) { }); ``` -### 4. How do you get the count of columns in the result set ? ### +### 4. How do you get the count of columns in the result set? ### -```js -client.query(..., function(err, result) { - var columnCount = Object.keys(result.rows[0]).length; -}); -``` - -This may also be accomplished using the `result.fields` array: ```js client.query(..., function(err, result) { var columnCount = result.fields.length;