From aaa45dfd1e2149be5a877bc2f74e8b110d6af406 Mon Sep 17 00:00:00 2001 From: whitelynx Date: Thu, 16 Oct 2014 09:21:05 -0700 Subject: [PATCH] Added alternate answer to #4, and made a minor correction to the original answer. --- FAQ.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/FAQ.md b/FAQ.md index d96893e..bf3a2a8 100644 --- a/FAQ.md +++ b/FAQ.md @@ -39,11 +39,18 @@ client.query(..., function(err, result) { ### 4. How do you get the count of columns in the result set ? ### ```js -pg.query(..., function(err, result) { +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; +}); +``` + ### 5. If pg returns query data in JSON format, for web service applications, it would make sense to return that directly to the client. If this assumption is correct what is the most efficient method? ### ```js