Skip to content

Doesn't seem to work with pool.query #159

@tswaters

Description

@tswaters

The examples don't make reference to this at all, but reading through the pg docs, there is a convenience utility on pool called query that is described here: https://node-postgres.com/apis/pool#poolquery

Often we only need to run a single query on the database, so as convenience the pool has a method to run a query on the first available idle client and return its result.

If used with pg-copy-stream, the result of the query will be a promise, not a stream.

const stream = pool.query(copyFrom(query))
stream.on // undefined :(

I looked at it with a debugger on, and it looks like a pending promise... I tried to await it, and it didn't come back, even with SELECT 1 as the query.

Here's some code that can repro this:

const pool = new pg.Pool({....etc })
const stream = pool.query(copyFrom(query))
stream.setEncoding('utf-8') // stream.setEncoding is not a function

I'm not sure if this is a bug necessarily, but maybe a note somewhere in the readme would save some struggling from future devs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions