-
Notifications
You must be signed in to change notification settings - Fork 862
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
分表查询被指定最后一个表名 #1945
Comments
看不太明白,如果不够用可以考虑用 WithTempQuery + UnionAll |
可以试试一下这两段代码: 第二段: |
要不提供完整一下完整的 console.csproj 项目。 |
问题描述及重现代码:
我需要实现查询多分表,SQL类似以下:
select * from table202412
union all
(
select * from table202411
)
........;
有以下代码实现:
ISelect select = null;
while (searchDate <= paraModel.QueryDate)
{
string tableName = $"public.{nameof(AttendanceRecord).ToLower()}{searchDate.Year * 100 + searchDate.Month}";
if (_freesql.DbFirst.ExistsTable(tableName))
{
tableNames.Add(tableName);
var lastselect = _freesql.Select()
.AsTable((t, s) => tableName)
;
if (select is null)
select = lastselect;
else
select = select.UnionAll(
lastselect
);
}
searchDate = searchDate.AddMonths(1);
}
当我的tablename在while循环里面显示定义的时候,可以达到我上述的查询目的。
当我的tablename在外部定义的时候,得到的SQL语句如下:
select * from table202412
union all
(
select * from table202412
)
..。。。
最终导致我只能查询一个分表的数据。
// c# code
数据库版本
pg13
安装的Nuget包
3.2.680
.net framework/. net core? 及具体版本
netcore
The text was updated successfully, but these errors were encountered: