0

I am having trouble executing this query

var insurers = [];  
var valid_insurer_query = plv8.execute('select * from table_name where row_id IN $1', [insurers])

It is giving syntax error

Error: syntax error at or near "$1"

It works fine if I use the query

var valid_insurer_query = plv8.execute('select * from table_name where row_id = $1', [insurer])  // here insurer is some entry from insurers.

I think it is creating trouble because psql query is unable to use javascript array as list. But I don't know how can I fix this issue ? Can anyone suggest some solution ? Can anyone share an example on how to use IN query in plv8 ?

4
  • You already seem to know the answer. Why don't you use the one that works? Commented May 15, 2020 at 16:57
  • Both of the statements have different purpose. Second one doesn't solve my purpose. I need to get the rows for which row_id is in the list. Commented May 16, 2020 at 5:48
  • Sorry, I somehow read your 2nd one as =ANY($1) rather than =$1 Commented May 16, 2020 at 14:03
  • Thanks. It works with =ANY($1) Commented May 16, 2020 at 15:00

1 Answer 1

1

I don't use plv8, but IN works with lists and lists can't be stored in parameters. What you appear to have is an array. For arrays, you use:

=ANY($1)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.