1

I have a simple sql query that can take in multiple arrays of type Integer, if I do something like this it works r.userid in(36,37,38) I left out some of the code since everything works correctly unless I try to pass it in as a List . I am new to npgsql so I am sure I am missing something any suggestions would be great .

This works

select s.post,s.fullname,s.location,s.streetplace,s.streetplace_id,s.profile_id as 
    ,s.link,s.title FROM streams s JOIN reshares r on r.userid in(36,37,38)

however if I do something like this

This does not work

var newList = new List<int>{ 36,37,38 };

   select s.post,s.fullname,s.location,s.streetplace,s.streetplace_id,s.profile_id as 
        ,s.link,s.title FROM streams s JOIN reshares r on r.userid in(@following)
  cmd.Parameters.AddWithValue("@following", newList);

I get the error

42883: operator does not exist: integer = integer[] at Npgsql.NpgsqlConnector.

No operator matches the given name and argument type(s). You might need to add explicit type casts.

1

1 Answer 1

2

In PostgreSQL, the IN operator is for rows, not arrays; to accomplish the same with arrays, you can use the ANY construct: WHERE x = ANY(@array).

Consult the full PostgreSQL docs here.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, that is exactly what was needed and will also look at docs.

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.