Count columns correctly even when the result set is empty

Charmander 2018-05-31 22:19:44 +00:00
parent 0c3453e2e6
commit f9dc8c82b6

9
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;