Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
43 lines (28 sloc) 1.28 KB
title slug
pg.Result
/api/result

The pg.Result shape is returned for every successful query.

note: you cannot instantiate this directly

properties

result.rows: Array<any>

Every result will have a rows array. If no rows are returned the array will be empty. Otherwise the array will contain one item for each row returned from the query. By default node-postgres creates a map from the name to value of each column, giving you a json-like object back for each row.

result.fields: Array<FieldInfo>

Every result will have a fields array. This array contains the name and dataTypeId of each field in the result. These fields are ordered in the same order as the columns if you are using arrayMode for the query:

const { Pool } = require('pg')

const pool = new Pool()

const client = await pool.connect()
const result = await client.query({
  rowMode: 'array',
  text: 'SELECT 1 as one, 2 as two;',
})
console.log(result.fields[0].name) // one
console.log(result.fields[1].name) // two
console.log(result.rows) // [1, 2]
await client.end()

result.rowCount: int

The number of rows processed by the last command.

result.command: string

The command type last executed: INSERT UPDATE CREATE SELECT etc.

You can’t perform that action at this time.