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.

user1591668
  • 2,591
  • 5
  • 41
  • 84
  • Does this answer your question? [Check if value exists in Postgres array](https://stackoverflow.com/questions/11231544/check-if-value-exists-in-postgres-array) – madreflection Apr 14 '21 at 18:52

1 Answers1

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.

Shay Rojansky
  • 15,357
  • 2
  • 40
  • 69