Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"WHERE x IN y" clause with dapper and postgresql throwing 42601: syntax error at or near \"$1\"

Tags:

I have an array of strings, and I'd like to have a query containing an IN clause, like:

"... WHERE t.name IN ('foo', 'bar', 'baz')..>"

Here's the final bit of my query, which contains a "where X in Y" clause:

...
left join genre_tag_band_join tj on hb.id = tj.band_id or ob.id = tj.band_id
left join genre_tags t on tj.genre_tag_id = t.id
inner join venues v on e.venue_id = v.id

where t.name IN @tagsParam...

I make a Dapper call like this

var shows = con.Query<Event, Band, Band, GenreTag, Venue, Event>(query, (e, hb, ob, gt, v) =>
{
    Event show;
    ...
    return e;
},
new { tagsParam = tagsArr}).AsQueryable();

where tagsArr is a string[].

I get exception:

{"42601: syntax error at or near \"$1\""}

like image 779
Sava B. Avatar asked Oct 18 '15 03:10

Sava B.


1 Answers

In PostgreSQL, you can't use IN to check whether a value is inside an array, you have to use the following PostgreSQL-specific syntax: where t.name = ANY (@tagsParam). See the section 8.15.5 in the PostgreSQL docs.

like image 110
Shay Rojansky Avatar answered Sep 28 '22 08:09

Shay Rojansky