How Can I Execute Multiple Queries in a Single Postgres Step Using NodeJS?

This topic was automatically generated from Slack. You can find the original thread here.

Is it possible to execute multiple queries in a single Postgres step?

I have tried connection pooling (nodejs code), combinedqueries, awaiting one to complete, etc. but I can’t seem to get it to work

I am needing to do this to first perform an increase of the statement_timeout, and then in the same session / connection run a separate query (which takes a few minutes to retrieve)
• If I ran this in two different steps, the statement timeout extension is only applied to the first step on Pipedream
Therefore trying to do this in one step to run multiple queries in one connection

Any help would be greatly appreciated

Example of the code I am trying to run

Although your code is pretty simple… not sure why it wouldn’t work. :thinking_face:

Here’s the code for the postgresql app, if it helps.

I think the problem is this line, which closes the connection.

So your second query is on a brand new connection.

image.png

You might want to call const client = await this.postgresql._getClient(); yourself, and then run your two queries on the same client/connection (using await client.query(query);).

Thanks for the help so far I have tried the getClient() a few times myself, and it returns the attached

So I’m not sure if this is even possible on Pipedream at all

image.png

Maybe you could try:

import pg from "pg";
const config = this.postgresql.getClientConfiguration();
const client = new pg.Client(config);

If this.postgresql.getClientConfiguration(); doesn’t work, then you could just build the configs yourself from this.postgresql.$auth. :man-shrugging:

Maybe you could try:

import pg from “pg”;

const config = this.postgresql.getClientConfiguration();
const client = new pg.Client(config);

This worked, thank you so much ! :tada: