我正在尝试将新数据集追加到已经存在的文件中。 我写的以下代码:
INSERT INTO analytic_filter_log_device(guest_device_id,query_filter_id,created_time) VALUES (UPDATE guest_device gd
SET status = false
FROM(
SELECT
gl.guest_device_id AS device_id
FROM guest_login gl
JOIN guest_device gd ON gd.id = gl.guest_device_id AND gd.status = TRUE
JOIN guest_login_ap gla ON gla.guest_login_id = gl.id
JOIN config_ap ca ON ca.id = gla.ap_id AND ca.company_id = 1
WHERE ('2018-06-26 00:00:00' IS NULL OR '2018-07-26 23:59:59' IS NULL OR (gla.start_time, gla.end_time) OVERLAPS ('2018-06-26 00:00:00', '2018-07-26 23:59:59')) AND
get_duration_in_interval(gla.start_time, gla.duration::bigint, '2018-06-26 00:00:00', '2018-07-26 23:59:59') >= 5
GROUP BY gl.guest_device_id
HAVING COUNT(DISTINCT gl.id) >= 5
) as t1
WHERE gd.id = t1.device_id
RETURNING 1,1,now());
但是每次它都在OUTPUT.csv文件夹中创建一个新文件时。 但是我的要求是始终将其添加到csv文件中,而不是创建一个新文件。有人认为有任何想法和更好的方法,因为合并在性能方面非常昂贵。