WhereRaw is not really raw?
spiralw opened this issue · 2 comments
I have the following SQL (postgres) query in Dapper:
await conn.QueryAsync(
"delete from group_members where id = any(@Groups)",
new { Groups = groups.Select(g => g.Id).ToArray() });
in SqlKata I tried to write it like this:
var query = new Query("group_members").AsDelete()
.WhereRaw($"group_id = any(?)", groups.Select(g => Id).ToArray()));
but this generates invalid SQL: DELETE FROM "group_members" WHERE group_id = any($1,$2)
. (I am not sure why it doesn't support arrays when Dapper does, but that is not the point of this issue).
I tried rewriting the SqlKata query like this:
var query = new Query("group_members").AsDelete()
.WhereRaw($"group_id = any(array[?])", groups.Select(g => Id).ToArray()));
This generates a different invalid query: DELETE FROM "group_members" WHERE group_id = any(array"@p0,@p1")
I don't understand why this happens. Why is [square brackets]
being changed to "quotation marks"
? The documentation seems to say square brackets is column syntax in SQL Server, so I tried adding a ForPostgreSql
to specify the SQL dialect i'm writing in, but that didn't change the result.
Hi, related to #407
oh, I see. thank you