querybuilder icon indicating copy to clipboard operation
querybuilder copied to clipboard

Unable to use a string array as a parameter in WhereRaw

Open wr-cdargis opened this issue 1 year ago • 1 comments

FYI I have seen issue #162

This is similar but I am trying to use .WhereRaw() with a string array.

This is the raw SQL I am trying to accomplish:

SELECT * FROM "v0"."Users" WHERE "Roles" && ('{"Member", "Admin"}');

My attempt at using SQL Kata looks like this

string str = String.Join(",", request.Roles.Select(r => $"\"{r.ToString()}\""));
str = $"'{{{str}}}'";
string raw = "\"Users\".\"Roles\" && (?)";
query = query.WhereRaw(raw, str);

The postgres server is telling me:

ERROR: operator does not exist: text[] && text;

The column I am querying is of type text[].

I have also tried just going totally RAW SQL without a parm, but that still isn't working:

string str = String.Join(",", request.Roles.Select(r => $"\"{r.ToString()}\""));
str = $"'{{{str}}}'";
string raw = $"\"Users\".\"Roles\" && ({str})";
query = query.WhereRaw(raw);

But my SQL ends up looking like this:

AND "Users"."Roles" && ('""Support","Admin""')

Looks like the {} chars are getting replaced with quotes?

wr-cdargis avatar Oct 02 '24 21:10 wr-cdargis

@wr-cdargis Any luck with this one? I am having the same issue with the latest version.

dmorales740 avatar May 13 '25 03:05 dmorales740