You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There's nothing built-in to support this but you can do it with a custom wrapper:
constDEFAULT_STATEMENT_TIMEOUT_MILLIS=10*1000;constpool=newpg.Pool({statement_timeout: DEFAULT_STATEMENT_TIMEOUT_MILLIS,});constcustomQuery=async(query,params)=>{constclient=awaitpool.connect();try{// Set our custom timeout:awaitclient.query('SET statement_timeout = 0');// Run the queryconstresult=awaitclient.query(query,params);// Revert the timeoutawaitclient.query(`SET statement_timeout = ${DEFAULT_STATEMENT_TIMEOUT_MILLIS}`);// All successful so release the connection:awaitclient.release();// Return back the actual result from the executed commandreturnresult;}catch(err){// Some error so discard the connectionawaitclient.release(err);// Bubble up the errorthrowerr;}}
Activity
sehrope commentedon Nov 29, 2019
There's nothing built-in to support this but you can do it with a custom wrapper:
charmander commentedon Nov 30, 2019
You could also have a separate pool for long queries. Its use of resources isn’t as nice, but it is simple.
dbauszus-glx commentedon Dec 1, 2019
That works great. I already had my query in an async function anyways. Thanks for your help.