I have a query of Postgresql-14 as below, the record was found if I run it on DBeaver 23.1.4.
I use:
- Dapper 2.0.143
- Npgsql 7.0.4
Npgsql.EntityFrameworkCore.PostgreSQL
7.0.4
Additional info:
process_datetime
and start_datetime
are of datatype timestamptz
.
What I don't understand is why it works properly on DBeaver 23.1.4?
I copy the query into a string variable named "sql", but I did not find the record if I run it on my Net Core 6 (C#) code, what I missed?
select
t.organizations_pid,
coalesce(sum(t.sum_usage),0) * 1.05 totalUsage,
coalesce(count(t.iccid), 0) numSIMs
from
(select
s.organizations_pid, c2.pid cdrs_pid, c2.cdr_id,
c2.iccid, c2.network, c1.sum_usage,
c2.start_datetime, c2.status
from
(select
s.organizations_pid, c1.iccid,
sum(c1.usage) sum_usage, max(c1.process_datetime) max_process_datetime
from
cdrs c1
inner join
sims s on c1.iccid = s.iccid
where
s.organizations_pid = 29
and to_char(c1.start_datetime,'YYYY-MM-DD') >= '2023-08-01'
and to_char(c1.start_datetime,'YYYY-MM-DD') <= '2023-08-07'
and c1.is_beginbal = false
group by
s.organizations_pid, c1.iccid) c1
inner join
cdrs c2 on c2.process_datetime = c1.max_process_datetime
and c2.iccid = c1.iccid
inner join
sims s on c2.iccid = s.iccid
and s.last_cdr_id = c2.cdr_id
inner join
organizations o on s.organizations_pid = o.pid
where
s.organizations_pid = 29
and s.attributes->'subscription'->> 'subscriptionStatus' = 'ACTIVE') t
group by
t.organizations_pid
My C# code is below:
using (var dr = conn.ExecuteReader(sql, new { }))
{
if (dr.Read())
{
double totalUsage = dr.GetDouble(dr.GetOrdinal("totalUsage"));
}
}
I also have tried below, but result returns null.
var result = conn.Query(sql, new { }).SingleOrDefault();