假设我想在两个日期之间生成一系列日期。我看到该功能generate_series仅提供
Function Argument Type Return Type Description
generate_series(start, stop, step interval) timestamp or timestamp with time zone setof timestamp or setof timestamp with time zone (same as argument type) Generate a series of values, from start to stop with a step size of step
Run Code Online (Sandbox Code Playgroud)
那么我该怎么做呢?
我使用的是 PostgreSQL V9.6.11
表DDL:
CREATE TABLE test_c (
insrt_prcs_id bigint NOT NULL,
updt_prcs_id bigint, src_sys_id integer NOT NULL,
load_dttm timestamp(6) with time zone NOT NULL,
updt_dttm timestamp(6) without time zone);
Run Code Online (Sandbox Code Playgroud)
我试图index为下面的查询创建一个:
SELECT *
FROM test_c
WHERE COALESCE(u_dttm,l_dttm) > '2020-04-10 15:29:44.596311-07'
AND COALESCE(u_dttm,l_dttm) <= '2020-04-11 15:29:44.596311-07'
Run Code Online (Sandbox Code Playgroud)
创建index为:
create index idx_test_c on test_c(COALESCE((updt_dttm, load_dttm)))
Run Code Online (Sandbox Code Playgroud)
但查询计划器没有扫描索引:
EXPLAIN ANALYZE
SELECT *
FROM test_c
WHERE COALESCE(u_dttm,l_dttm) > '2020-04-10 15:29:44.596311-07'
AND COALESCE(u_dttm,l_dttm) <= '2020-04-11 15:29:44.596311-07'
Run Code Online (Sandbox Code Playgroud)
Seq Scan on test_c as test_c (cost=0..1857.08 …Run Code Online (Sandbox Code Playgroud)