postgresql where .. in error
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 18.4k
- Forks
- 3.7k
- Avg merge
- 5h 8m
- Merged PRs (30d)
- 1
Description
My sql where usercode in @usercodes",new {usercodes=new string[]{"1","2"} failed in dapper with npgsql。
List Support
Dapper allows you to pass in IEnumerable<int> and will automatically parameterize your query.
For example:
connection.Query<int>("select * from (select 1 as Id union all select 2 union all select 3) as X where Id in @Ids", new { Ids = new int[] { 1, 2, 3 } });
Will be translated to:
select * from (select 1 as Id union all select 2 union all select 3) as X where Id in (@Ids1, @Ids2, @Ids3)" // @Ids1 = 1 , @Ids2 = 2 , @Ids2 = 3
The docs says that the array params will be translated to like Id in (@Ids1, @Ids2, @Ids3). But I find that it is not when I debug the dapper csproj . In
在 Dapper.SqlMapper.ExecuteReaderWithFlagsFallback(IDbCommand cmd, Boolean wasClosed, CommandBehavior behavior) 在 F:\Download\Dapper-main\Dapper-main\Dapper\SqlMapper.cs 中: 第 1066 行

The image shows that the commandText is in @usercodes, but not like in (@Ids1, @Ids2, @Ids3) as the docs says.
--------------- 2022-06-16 14:25:53 -----------------
I found that it was transleted in oracle ,but not in pgsql. Can it be trans in pgsql too?

Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The report points to Dapper/SqlMapper.cs around line 1066 and compares PostgreSQL/Npgsql behavior with the documented list-parameter example. Start by reproducing the query with a string[] usercodes value and inspect commandText; done means the PostgreSQL result matches the documented IN expansion, or the provider-specific limitation is clearly established.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, postgresql
- Domain
- database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100