我怎样才能使这个日期输入在 PostgreSQL 查询中起作用?
How can i make this date input in a PostgreSQL query to work?
我正在处理一个具有一系列连接并从中获取信息的查询,如下所示:
SELECT
fleet."name" AS "Fleet",
wp."tail" AS "AC",
wp."iata" AS "LOC",
CONCAT(usrr."firstName", ' ', usrr."lastName") AS "Supervisor",
CONCAT(usr."firstName", ' ', usr."lastName") AS "Mechanic",
to_char(wp."req" AT TIME ZONE 'utc' AT TIME ZONE airbase."timeZone", :format) AS "ETA",
to_char(wp."etr" AT TIME ZONE 'utc' AT TIME ZONE airbase."timeZone", :format) AS "ETD",
round(cast(date_part('hour', age(wp."etr", wp."req")) / 24 AS NUMERIC), 2) AS TAT,
NULL AS "Position",
wp."barcode" AS "WP",
breq."barcode" AS "REQ/BLOQ",
breq."name" AS "REQ Name",
jic."barcode" AS "Task BC",
jic."description" AS "Task Name",
jic."due_date" AS "Due date",
labor."name" AS "Skills",
CASE WHEN date_part('hour', age(jic."estimated_end_date", jic."estimated_start_date")) > 0
AND date_part('minute', age(jic."estimated_end_date", jic."estimated_start_date")) > 0
THEN date_part('hour', age(jic."estimated_end_date", jic."estimated_start_date")) +
date_part('minute', age(jic."estimated_end_date", jic."estimated_start_date")) * 0.01
WHEN date_part('hour', age(jic."estimated_end_date", jic."estimated_start_date")) > 0
AND date_part('minute', age(jic."estimated_end_date", jic."estimated_start_date")) = 0
THEN date_part('hour', age(jic."estimated_end_date", jic."estimated_start_date"))
WHEN date_part('hour', age(jic."estimated_end_date", jic."estimated_start_date")) = 0
AND date_part('minute', age(jic."estimated_end_date", jic."estimated_start_date")) > 0
THEN date_part('minute', age(jic."estimated_end_date", jic."estimated_start_date")) * 0.01
WHEN date_part('hour', age(jic."estimated_end_date", jic."estimated_start_date")) = 0
AND date_part('minute', age(jic."estimated_end_date", jic."estimated_start_date")) = 0
THEN date_part('hour', age(jic."estimated_end_date", jic."estimated_start_date"))
END AS "Duration",
jic."resources_quantity" AS "nTec",
CASE WHEN date_part('hour', age(jic."estimated_end_date", jic."estimated_start_date")) > 0
AND date_part('minute', age(jic."estimated_end_date", jic."estimated_start_date")) > 0
THEN date_part('hour', age(jic."estimated_end_date", jic."estimated_start_date")) +
date_part('minute', age(jic."estimated_end_date", jic."estimated_start_date")) * 0.01 *
jic."resources_quantity"
WHEN date_part('hour', age(jic."estimated_end_date", jic."estimated_start_date")) > 0
AND date_part('minute', age(jic."estimated_end_date", jic."estimated_start_date")) = 0
THEN date_part('hour', age(jic."estimated_end_date", jic."estimated_start_date")) * jic."resources_quantity"
WHEN date_part('hour', age(jic."estimated_end_date", jic."estimated_start_date")) = 0
AND date_part('minute', age(jic."estimated_end_date", jic."estimated_start_date")) > 0
THEN date_part('minute', age(jic."estimated_end_date", jic."estimated_start_date")) * 0.01 *
jic."resources_quantity"
WHEN date_part('hour', age(jic."estimated_end_date", jic."estimated_start_date")) = 0
AND date_part('minute', age(jic."estimated_end_date", jic."estimated_start_date")) = 0
THEN date_part('hour', age(jic."estimated_end_date", jic."estimated_start_date")) * jic."resources_quantity"
END AS "MH",
to_char(jic.estimated_start_date AT TIME ZONE 'utc' AT TIME ZONE airbase."timeZone", :format) AS "Start",
to_char(jic.estimated_end_date AT TIME ZONE 'utc' AT TIME ZONE airbase."timeZone", :format) AS "End",
usr.bp AS "BP",
CASE WHEN breq.is_productive = 1 AND breq.task_type_id != 3
THEN 'PROD'
WHEN breq.is_productive = 0 or breq.task_type_id = 3
THEN 'NPROD' END AS "Tipo",
work_location."name" AS "Zone",
breq."review_status" AS "Acceptance",
CASE WHEN wp."published" = TRUE
THEN 'PUBLISHED'
WHEN wp."published" = FALSE
THEN 'UNPUBLISHED' END AS "Published"
FROM public."work_package" AS wp
INNER JOIN public."task" AS breq ON wp."id" = breq."work_package_id"
INNER JOIN public."labor" AS jic ON breq."id" = jic."task_id"
LEFT JOIN public."Skill" AS labor ON jic."skill_id" = labor."id"
LEFT JOIN public."user_labor" AS usr_l ON jic."id" = usr_l."labor_id"
LEFT JOIN public."User" AS usr ON usr_l."user_id" = usr."id"
LEFT JOIN public."Aircraft" AS aircraft ON wp."aircraft_id" = aircraft."id"
LEFT JOIN public."Fleet" AS fleet ON aircraft."fleetId" = fleet."id"
left JOIN public."Airbase" as airbase ON wp.base_id = airbase.id
LEFT JOIN public."BSE_WORK_LOCATIONS" AS work_location ON wp."work_location_id" = work_location."id"
LEFT JOIN public."User" AS usrr ON wp."supervisor_user_id" = usrr."id"
WHERE wp."start" BETWEEN to_timestamp(:start) AND to_timestamp(:finish) OR wp."end"
BETWEEN to_timestamp(:start) AND to_timestamp(:finish);
该脚本由对不同 table 的不同字段的调用组成,然后对某些字段使用 case,调用插入格式以构建部分输出的输入,最后,我正在测试的 WHERE 语句关闭了对更有限的东西的调用。冲突位是最后一部分,带有 WHERE 语句。我使用了许多不同的方法,例如:模仿 table 在该字段上的相同结构,使用和不使用引号,使用 utc 时区,使用毫秒,直到现在都没有任何效果。原始字段具有时间戳类型,这就是我在那里使用解析的原因。这是在 DataGrip 上查看的输入:
到现在为止,在我删除引号后,它将完成该过程,但它什么也不会 return,即使我知道那里有数据。
有没有明显的地方我做错了?请帮忙。提前致谢!
因为该字段是一个时间戳,PostgreSQL 从具有以下格式的字符串反序列化一个:'YYYY-MM-DD HH:MM:SS.M'
(注意单引号)。然后就可以正常使用了。
我正在处理一个具有一系列连接并从中获取信息的查询,如下所示:
SELECT
fleet."name" AS "Fleet",
wp."tail" AS "AC",
wp."iata" AS "LOC",
CONCAT(usrr."firstName", ' ', usrr."lastName") AS "Supervisor",
CONCAT(usr."firstName", ' ', usr."lastName") AS "Mechanic",
to_char(wp."req" AT TIME ZONE 'utc' AT TIME ZONE airbase."timeZone", :format) AS "ETA",
to_char(wp."etr" AT TIME ZONE 'utc' AT TIME ZONE airbase."timeZone", :format) AS "ETD",
round(cast(date_part('hour', age(wp."etr", wp."req")) / 24 AS NUMERIC), 2) AS TAT,
NULL AS "Position",
wp."barcode" AS "WP",
breq."barcode" AS "REQ/BLOQ",
breq."name" AS "REQ Name",
jic."barcode" AS "Task BC",
jic."description" AS "Task Name",
jic."due_date" AS "Due date",
labor."name" AS "Skills",
CASE WHEN date_part('hour', age(jic."estimated_end_date", jic."estimated_start_date")) > 0
AND date_part('minute', age(jic."estimated_end_date", jic."estimated_start_date")) > 0
THEN date_part('hour', age(jic."estimated_end_date", jic."estimated_start_date")) +
date_part('minute', age(jic."estimated_end_date", jic."estimated_start_date")) * 0.01
WHEN date_part('hour', age(jic."estimated_end_date", jic."estimated_start_date")) > 0
AND date_part('minute', age(jic."estimated_end_date", jic."estimated_start_date")) = 0
THEN date_part('hour', age(jic."estimated_end_date", jic."estimated_start_date"))
WHEN date_part('hour', age(jic."estimated_end_date", jic."estimated_start_date")) = 0
AND date_part('minute', age(jic."estimated_end_date", jic."estimated_start_date")) > 0
THEN date_part('minute', age(jic."estimated_end_date", jic."estimated_start_date")) * 0.01
WHEN date_part('hour', age(jic."estimated_end_date", jic."estimated_start_date")) = 0
AND date_part('minute', age(jic."estimated_end_date", jic."estimated_start_date")) = 0
THEN date_part('hour', age(jic."estimated_end_date", jic."estimated_start_date"))
END AS "Duration",
jic."resources_quantity" AS "nTec",
CASE WHEN date_part('hour', age(jic."estimated_end_date", jic."estimated_start_date")) > 0
AND date_part('minute', age(jic."estimated_end_date", jic."estimated_start_date")) > 0
THEN date_part('hour', age(jic."estimated_end_date", jic."estimated_start_date")) +
date_part('minute', age(jic."estimated_end_date", jic."estimated_start_date")) * 0.01 *
jic."resources_quantity"
WHEN date_part('hour', age(jic."estimated_end_date", jic."estimated_start_date")) > 0
AND date_part('minute', age(jic."estimated_end_date", jic."estimated_start_date")) = 0
THEN date_part('hour', age(jic."estimated_end_date", jic."estimated_start_date")) * jic."resources_quantity"
WHEN date_part('hour', age(jic."estimated_end_date", jic."estimated_start_date")) = 0
AND date_part('minute', age(jic."estimated_end_date", jic."estimated_start_date")) > 0
THEN date_part('minute', age(jic."estimated_end_date", jic."estimated_start_date")) * 0.01 *
jic."resources_quantity"
WHEN date_part('hour', age(jic."estimated_end_date", jic."estimated_start_date")) = 0
AND date_part('minute', age(jic."estimated_end_date", jic."estimated_start_date")) = 0
THEN date_part('hour', age(jic."estimated_end_date", jic."estimated_start_date")) * jic."resources_quantity"
END AS "MH",
to_char(jic.estimated_start_date AT TIME ZONE 'utc' AT TIME ZONE airbase."timeZone", :format) AS "Start",
to_char(jic.estimated_end_date AT TIME ZONE 'utc' AT TIME ZONE airbase."timeZone", :format) AS "End",
usr.bp AS "BP",
CASE WHEN breq.is_productive = 1 AND breq.task_type_id != 3
THEN 'PROD'
WHEN breq.is_productive = 0 or breq.task_type_id = 3
THEN 'NPROD' END AS "Tipo",
work_location."name" AS "Zone",
breq."review_status" AS "Acceptance",
CASE WHEN wp."published" = TRUE
THEN 'PUBLISHED'
WHEN wp."published" = FALSE
THEN 'UNPUBLISHED' END AS "Published"
FROM public."work_package" AS wp
INNER JOIN public."task" AS breq ON wp."id" = breq."work_package_id"
INNER JOIN public."labor" AS jic ON breq."id" = jic."task_id"
LEFT JOIN public."Skill" AS labor ON jic."skill_id" = labor."id"
LEFT JOIN public."user_labor" AS usr_l ON jic."id" = usr_l."labor_id"
LEFT JOIN public."User" AS usr ON usr_l."user_id" = usr."id"
LEFT JOIN public."Aircraft" AS aircraft ON wp."aircraft_id" = aircraft."id"
LEFT JOIN public."Fleet" AS fleet ON aircraft."fleetId" = fleet."id"
left JOIN public."Airbase" as airbase ON wp.base_id = airbase.id
LEFT JOIN public."BSE_WORK_LOCATIONS" AS work_location ON wp."work_location_id" = work_location."id"
LEFT JOIN public."User" AS usrr ON wp."supervisor_user_id" = usrr."id"
WHERE wp."start" BETWEEN to_timestamp(:start) AND to_timestamp(:finish) OR wp."end"
BETWEEN to_timestamp(:start) AND to_timestamp(:finish);
该脚本由对不同 table 的不同字段的调用组成,然后对某些字段使用 case,调用插入格式以构建部分输出的输入,最后,我正在测试的 WHERE 语句关闭了对更有限的东西的调用。冲突位是最后一部分,带有 WHERE 语句。我使用了许多不同的方法,例如:模仿 table 在该字段上的相同结构,使用和不使用引号,使用 utc 时区,使用毫秒,直到现在都没有任何效果。原始字段具有时间戳类型,这就是我在那里使用解析的原因。这是在 DataGrip 上查看的输入:
到现在为止,在我删除引号后,它将完成该过程,但它什么也不会 return,即使我知道那里有数据。
有没有明显的地方我做错了?请帮忙。提前致谢!
因为该字段是一个时间戳,PostgreSQL 从具有以下格式的字符串反序列化一个:'YYYY-MM-DD HH:MM:SS.M'
(注意单引号)。然后就可以正常使用了。