mirror of
https://github.com/brianc/node-postgres.git
synced 2026-01-18 15:55:05 +00:00
Count columns correctly even when the result set is empty
parent
0c3453e2e6
commit
f9dc8c82b6
9
FAQ.md
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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user