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.

Working with = ANY ($1) with array binding fails in Redshift

See original GitHub issue

Here is my test. Apologies, I don’t have a Redshift database available that you can use to test. You’ll need a Redshift database with table “table_with_ids” with column “my_id” and 2 rows:

my_id

1 2

Here is my code:

const pg = require('pg');

const query = `
   SELECT count(1) 
     FROM table_with_ids
    WHERE my_id = ANY ($1)`;

const config = {
    // need connection to Redshift database...
};

// instantiate a new client with config
const client = new pg.Client(config);

const bindVars = [[1,2]];

// connect to our database
client.connect((err) => {
    if (err) throw err;

    // execute a query on our database
    client.query(query, bindVars, (err2, result) => {
        if (err2) {
            console.log(err2.detail); // shows odd error
            throw err2;
        }

        // just print the result to the console
        console.log(result.rows[0]); // should output: { count: 2 }

        // disconnect the client
        client.end((err3) => {
            if (err3) throw err3;
        });
    });
});

Here is the text returned from the “console.log(err2.detail)” statement:

  -----------------------------------------------
  error:  Assert
  code:      1000
  context:   IsA((Node*)arrayExpr->args->tail->data.ptr_value,Const) - 
  query:     509314
  location:  xen_execute.cpp:5593
  process:   padbmaster [pid=20170]
  -----------------------------------------------

Here is the stack trace of the error returned:

error: Assert
    at Connection.parseE (/my-project-root/node_modules/pg/lib/connection.js:554:11)
    at Connection.parseMessage (/my-project-root/node_modules/pg/lib/connection.js:381:17)
    at Socket.<anonymous> (/my-project-root/node_modules/pg/lib/connection.js:117:22)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at readableAddChunk (_stream_readable.js:176:18)
    at Socket.Readable.push (_stream_readable.js:134:10)
    at TCP.onread (net.js:548:20)

pg version: 6.1.2 node version: 6.9.2

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
PranaviCcommented, May 7, 2018

I faced the same issues and managed to get it working with the below code using https://github.com/lib/pq

v, _ := pq.Array([]int{1,2,3}).Value()
query := fmt.Sprintf(`select * from table where colID = any('%v'::integer[]);`, v)
rows, err := db.Query(query)

Hope it helps someone in the future!

0reactions
yieldinovcommented, May 24, 2017

@keithrz, hey! Did you solve your problem?

Read more comments on GitHub >

github_iconTop Results From Across the Web

CREATE VIEW - Amazon Redshift
Creates a view in a database. The view isn't physically materialized; the query that defines the view is run every time the view...
Read more >
Multi-Select fails with redshift queries prepared statements
This was an interesting method to try but it still fails. This works company = any( string_to_array('Tricon American Homes,Cinch Home ...
Read more >
Does RedShift Postgresql support Bind variable?
I am accessing AWS RedShift through DBI and DBD::Pg module in Perl and I have some trouble with SQL bind variable. I call...
Read more >
Querying semistructured data - Amazon Redshift
In Amazon Redshift, you can work with the PartiQL language for SQL-compatible ... The PartiQL syntax uses dotted notation and array subscript for...
Read more >
Best Practices, Considerations, and Requirements for Using ...
Therefore, Rivery requires to use WITH NO SCHEMA BINDING clause when creating ... However, the array type isn't so flexible in Redshift and...
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