添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
  • API
  • pg.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:

import pg from 'pg'
const { Pool } = 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.command: string

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

result.rowCount: int | null