Working with = ANY ($1) with array binding fails in Redshift
See original GitHub issueHere 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:
- Created 7 years ago
- Comments:5 (1 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I faced the same issues and managed to get it working with the below code using https://github.com/lib/pq
Hope it helps someone in the future!
@keithrz, hey! Did you solve your problem?