c# - Dapper.net "where ... in" query doesn't work with PostgreSQL -
the following query produces error "42601: syntax error @ or near "$1" ".
connection.query<carstatsprojection>( @"select manufacturer, model, year, avg(price) averageprice, avg(miles) averagemiles, count(*) count products manufacturer in @manufacturers , model in @models , year in @years group manufacturer, model, year", new { manufacturers = new[] { "bmw", "audi" }, models = new[] { "m4", "a3" }, years = new[] { 2016, 2015 } });
i have got around creating method below , calling inline build sql query now. know if dapper can handle object param though?
public static string toinsql(this ienumerable<object> values) { var flattened = values.select(x => $"'{x}'"); var flatstring = string.join(", ", flattened); return $"({flatstring})"; }
postgresql in
operator doesn't support array (or other collection) parameter, normal list (the 1 you're generating toinsql
method), postgresql need use any
operator, this:
select manufacturer, model, year, avg(price) averageprice, avg(miles) averagemiles, count(*) count products manufacturer = any(@manufacturers) , model = any(@models) , year = any(@years) group manufacturer, model, year
Comments
Post a Comment