I try to fetch an execution plan from Postgresql via Npgsql and Dapper.
And versions of used software.
- .Net Framework 4.6.1
- ASP.NET WebAPI 2
- Postgresql 9.4
- Npgsql v3.0.5
- Dapper v1.42.0
Non-EXPLAIN query with IN-clause with List<int> can fetch rows.
ex: SELECT 1 FROM banana WHERE banana_id IN @BananaIdList
But with EXPLAIN query throws followed Npgsql.NpgsqlException 42601: syntax error at or near \"$1\"
.
ex: EXPLAIN SELECT 1 FROM banana WHERE banana_id IN @BananaIdList
Why EXPLAIN syntax with IN-clause causes NpgsqlException?
Can I fetch execution plan?
.
I wrote a simple program for reproduce.
Running on Console project and WebAPI2 throws same Exception.
public class BadQuery {
public async Task Test() {
const string Sql = "EXPLAIN SELECT 1 FROM banana WHERE banana_id IN @BananaIdList";
var parameters = new DynamicParameters();
parameters.Add("@BananaIdList", new List<int> {1, 2, 3});
var conn = new NpgsqlConnection("Server=127.0.0.1; Port=******; Database=******; User Id=******; Password=******;");
conn.Open();
var results = await conn.QueryAsync<string>(Sql, parameters); // throws NpgsqlException
}
}
I found a similar question, but this question uses Array[].
"WHERE x IN y" clause with dapper and postgresql throwing 42601: syntax error at or near \"$1\"
Thanks.