2

I know that a question like this already exists in: How to pass parameter to sql 'in' statement?

but the answers didn't help me, so I am asking for your guidance.

How do you pass a string array as parameter to a Npgsql statement? Let's say the statement goes something like this:

string[] names = new string[] { "one", "two" };

Adapter.SelectCommand.CommandText("Select something.name from something (a lot of inner joins) where something_else.name in (:names) group by something.name having count(*)=2; ");

2 Answers 2

2

Try:

where something_else.name = any(:names)
Sign up to request clarification or add additional context in comments.

Comments

0

I am not familiar with the exact syntax of npgsql, but I can tell you how to proceed.

From your string array names create a string that looks like "'one', 'two'". Be sure you have the single quotes delimited them.

Then, when you create the command string, don't use variable substitution. Instead, just concatenate the string you just created between the ( and ) after the in statement. That is, directly insert them into the string.

1 Comment

That was a solution I wanted to follow, but I kinda didn't want to bother myself with concatenating strings and such. Thanks for reply!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.