Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WhereRaw is not really raw? #528

Closed
ghost opened this issue Sep 29, 2021 · 2 comments
Closed

WhereRaw is not really raw? #528

ghost opened this issue Sep 29, 2021 · 2 comments

Comments

@ghost
Copy link

ghost commented Sep 29, 2021

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.

@ahmad-moussawi
Copy link
Contributor

Hi, related to #407

@ghost
Copy link
Author

ghost commented Sep 29, 2021

oh, I see. thank you

@ghost ghost closed this as completed Sep 29, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant