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

pgsql数据库查询返回54011 ROW expressions can have at most 1664 entries #1972

Open
peng951 opened this issue Feb 6, 2025 · 6 comments

Comments

@peng951
Copy link

peng951 commented Feb 6, 2025

问题描述及重现代码:

// c# code
//先定义一个部门列表
public class Department
{
        /// <summary>
        /// 组织架构Id
        /// </summary>
        [Column(IsPrimary  = true)]
        public int DepartmentId { get; set; }
      
}

//代码查询部分
public void action(object parama)
{
            var depList = new List<int>();
            for (int i = 0; i < 50000; i++)
            {
                depList.Add(i);
            }
            var depselect = await  _freesql.Select<Department>()
                .WhereIf(true, x => depList != null && depList.Contains(x.DepartmentId))
                .ToListAsync();
}
调上面这个方法返回"54011: ROW expressions can have at most 1664 entries\r\n\r\nPOSITION: 265"
看一下翻译过来的sql,大概意思是
select * from department a where (0,1,2,......4999) is not null and a.departmentid in (0,1,2,......4999)导致数据库层面报54011

![Image](https://github.com/user-attachments/assets/3995689d-32a7-48cf-ad1f-8211883b1bb8)

#### 数据库版本
pg13

#### 安装的Nuget包
3.2.680

#### .net framework/. net core? 及具体版本
net8
@2881099
Copy link
Collaborator

2881099 commented Feb 6, 2025

whereif 换一种写法,不要用 true,你先想一下

@peng951
Copy link
Author

peng951 commented Feb 6, 2025

whereif 换一种写法,不要用 true,你先想一下

换一种写法能实现。只是这个层面能不能优化一下。depList != null把这个条件去掉就可以了。

@2881099
Copy link
Collaborator

2881099 commented Feb 6, 2025

把这个条件放在第一个参数不就可以了

@peng951
Copy link
Author

peng951 commented Feb 7, 2025

把这个条件放在第一个参数不就可以了

可以是可以。只是业务环境复杂,而且代码也不是我一个人维护的。我上面的那个demo只是一个能完全复现的方法

@luoyunchong
Copy link
Collaborator

使用问题,因为这个逻辑会转换成SQL,你应该在代码验证业务数据

@2881099
Copy link
Collaborator

2881099 commented Feb 7, 2025

按规定的来写,基本常识了,就像 my name is xxx 不能写成 my name are xxx 一样。

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

3 participants