brianc / node-pg-cursor

Query cursor extension for node-postgres

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Redshift: anyone knows?

unlucio opened this issue · comments

Hello,
I was trying to use this against a redshift instance with the following test script:

const { Pool } = require('pg');
const config = require('./src/lib/config');
const credentials = config.get('warehousedb');

const pool = new Pool({
    user: credentials.user,
    host: credentials.host,
    database: credentials.name,
    password: credentials.pass,
    port: credentials.port
});

function consumeCursor(cursor, cb, done) {
    console.log('consumeCursor invocation');
    cursor.read(100, (error, rows) => {
        if (error) {
            done(error);
            return;
        }

        if (rows.length < 1 ) {
            console.log('Cursor is empty, all done!');
            done();
            return;
        }

        cb(rows);
        consumeCursor(cursor, cb, done);
    });
}

const query = 'select * from <table_name> LIMIT 1000';

pool.connect().then(function(client) {
    console.log('creating cursor');
    const cursor = client.query(new Cursor(query));

    function done(error) {
        if (error) {
            console.error('Cursor boom: ', error);
        }

        console.log('done!');
        cursor.close(() => client.release());
    }

    function push(result = []) {
        console.log('Got results: ', result.length);
    }

    consumeCursor(cursor, push, done);
});

and behold of the result:

creating cursor
consumeCursor invocation
Got results:  1000
consumeCursor invocation
Cursor is empty, all done!
done!

So here's what's confusing me:

  • As shown from Got results: 1000 I guess Redshift might not be playing ball?
  • Now, why Got results: 1000 if I'm asking to read 100 items? I tried removing the LIMIT 1000 as well but there was no change.

I haven't got any time yet to read node-pg-cursor yet so I def might be miss-understanding something, so apologie for something I might have missed.

ok, seems like this might be the answer to my questions https://github.com/brianc/node-pg-cursor/blob/master/index.js#L138 :/ 🤷‍♂️

I assume no one else is interested in a redshift support?

@unlucio did you see #14? PR #44 might solve your problem.

Hi,

It's any of the maintainers planning to merge PR #44? I also tested locally and the new changes from #44 seems to fix the Streaming issues.