1、问题
同样的sql,执行思路,在测试环境,可以正常获取结果,生产环境数据就是不对,怀疑是PG版本不同。
sql如下:
xx的意思:查询completion_date,6天后的日期(跳过节假日),结果数据都没有转换
SELECT distinct
A.input_user,
A.acqtn_mode,
A.assemble_id AS zhy_zydx,
A.completion_date,
((
select
cast(rq as varchar)
from
dquality_ycbf.zl_weekday
where
rq >= to_date (cast(A.completion_date as varchar), 'yyyy-MM-dd')
and sfjjr = 'N'
order by
rq asc
offset
6
limit
1
) || SUBSTRING( cast(cast(A.completion_date as varchar) as varchar),11,10)
) as xx
FROM
std_data.xx_item A
where
(
(
A.Input_Time >= '2024-07-01 00:00:00'
and A.Input_Time <= '2024-09-30 23:59:59'
)
or (
A.Update_Date >= '2024-07-01 00:00:00'
and A.Update_Date <= '2024-09-30 23:59:59'
)
)
and A.dataset_class in ('A0100000000002', 'a0100000000002')
and A.test_item_id = A.test_item_id
1.1生产环境
正常来讲xx,数据要么是null, 要么比completion_date至少大6天,莫名奇妙出来哦2023-03-27不能理解。
执行计划
生产环境,执行计划,看用到了HashAggregate ,不知道是不是它的影响。搞不懂,先放着,希望以后能明白原因
1、2测试环境
测试环境转的也很正常。
方案修改
研究半天搞不懂,生产环境为什么不行。于是决定修改方案。 先找到zl_weekday表rq,对应跳过N天之后的实际日期,然后比较
SELECT
A.input_user,
A.acqtn_mode,
A.assemble_id AS zhy_zydx,
A.completion_date,
( (
select
cast(real_rq as varchar)
from
( select rq,(select d1.rq from dquality_ycbf.zl_weekday d1
where d1.rq>=zw.rq
and d1.sfjjr = 'N'
order by
d1.rq asc
offset
6
limit
1)as real_rq
from dquality_ycbf.zl_weekday zw) xx
where
xx.rq = to_date (cast(A.completion_date as varchar), 'yyyy-MM-dd')
) || SUBSTRING( cast(cast(A.completion_date as varchar) as varchar),11,10)
) as xx
FROM
std_data.com_analysis_item A
where
(
(
A.Input_Time >= '2024-07-01 00:00:00'
and A.Input_Time <= '2024-09-30 23:59:59'
)
or (
A.Update_Date >= '2024-07-01 00:00:00'
and A.Update_Date <= '2024-09-30 23:59:59'
)
)
and A.dataset_class in ('A0100000000002', 'a0100000000002')
这个方案,生产环境和测试环境都可以正确查到数据
标签:completion,00,转换,rq,查询,cast,pg,date,varchar From: https://blog.csdn.net/s07aser123/article/details/142637598