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

Error when use in #52

Open
Genuineh opened this issue Apr 28, 2022 · 3 comments
Open

Error when use in #52

Genuineh opened this issue Apr 28, 2022 · 3 comments
Assignees

Comments

@Genuineh
Copy link

Code

using var cnn = new ClickHouseConnection(settings.ToString());

await cnn.OpenAsync().ConfigureAwait(false);

var cmd = cnn.CreateCommand("SELECT * FROM cktest WHERE id IN ({ids})");
cmd.Parameters.AddWithValue("ids", new long[] { 1, 2 });

var res = await cmd.ExecuteReaderAsync().ConfigureAwait(false);

Error

Octonica.ClickHouseClient.Exceptions.ClickHouseServerException : DB::Exception: Table test._b518ecd58bd34345b613ae87297fa501 doesn't exist

@victor-sushko
Copy link
Contributor

Hello, @Genuineh

The right side of IN operator may be either a set of constant expressions or a table (see IN Operators for details).

You may modify your query and pass the array of values as a table with a single column:

using var cnn = new ClickHouseConnection(settings.ToString());

await cnn.OpenAsync().ConfigureAwait(false);

var cmd = cnn.CreateCommand("SELECT * FROM cktest WHERE id IN ids");

var ids = new long[] { 1, 2 };
var tableProvider = new ClickHouseTableProvider("ids", ids.Length);
tableProvider.AddColumn(ids);
cmd.TableProviders.Add(tableProvider);

var res = await cmd.ExecuteReaderAsync().ConfigureAwait(false);

@Genuineh
Copy link
Author

Hi, @victor-sushko
Thanks for your replay, it work right.

@Genuineh Genuineh reopened this Apr 29, 2022
@Genuineh
Copy link
Author

Genuineh commented Apr 29, 2022

hi, @victor-sushko
I got error when i want to use dapper style sql like "in @ids"

code

await cnn.QueryAsync<object>("SELECT * FROM cktest WHERE id IN @ids", new { ids = new[] { 1L, 2L } });

error

Octonica.ClickHouseClient.Exceptions.ClickHouseServerException : DB::Exception: Types of column 1 in section IN don't match: Int64 on the left, Array(Int64) on the right

Whether not support array parameters with dapper style

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

2 participants