question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is there a way to pause and resume query output?

See original GitHub issue

I’m using the eventEmitter model to handle the results from a query that produces a large number of rows. The handler has some async components, so I’d really like to be able to keep the next ‘row’ event from firing until after the current one has completed processing.

Ideally this would take to form of pause() and resume() calls on the query object itself.

 var query = client.query("select * from big_data_table");
 query.on('row', function (row) {
    query.pause(); // turn off the firehose
    return do_something_async(row, function() {
      query.resume(); // turn back on the firehose
    });
 });

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Reactions:1
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
TeddyPerkins77commented, Jun 1, 2016

@brianc thank you for quick response! I ended up using query-stream.

@jgoux this worked for me buddy:

var QueryStream = require('pg-query-stream')
var pg = require('pg')

var conString = "yourConnectionString";
var client = new pg.Client(conString);

client.connect(function(err) {
       if(err) {
             return console.error('could not connect to postgres', err);
        }

    if(err) throw err;
    var query = new QueryStream(queryStr, values)
    var stream = client.query(query)

    stream.on('data', function(row) {
        stream.pause();
            //handle your async process here
        stream.resume();
    })
    stream.on('end', function() {
        client.end();
    })
});

Cheers!

1reaction
jgouxcommented, May 31, 2016

I’m interested as well. I’d like to handle an async process inside the data handler, and receive the next row only when my async process in the handler is over.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Pause or Resume a Database Mirroring Session (SQL Server)
Learn how to pause and resume a SQL Server database mirroring session using SQL Server ... From the Standard bar, click New Query....
Read more >
Is it possible to pause an SQL query? - Stack Overflow
I'm assuming the answer is 'NO' because of how rows and data gets locked, etc. I'm using Sql Server 2008, btw. tsql ·...
Read more >
Automatic Pause and Resume of an Azure SQL database
This article will show how to automatic Pause and Resume an Azure SQL database.
Read more >
sql server - Pause and resume execution of stored procedure
There's no clean way to just pause and resume a stored procedure, but you can have it sleep for a fixed period of...
Read more >
Pause or Cancel a Search - Sumo Logic Docs
You can resume a paused search; just click Resume under the Start button. Cancel a Search​. When you cancel a search, you are...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found