CREATE TABLE history_0 AS
WITH moved_rows AS (
DELETE FROM current
WHERE current.date < (now() - '6 Months'::interval)
RETURNING * -- or specify columns
)
SELECT * FROM moved_rows;
WITH RECURSIVE t AS (
( SELECT flows.hostname
FROM flows
ORDER BY flows.hostname
LIMIT 1)
UNION ALL
SELECT ( SELECT flows.hostname
FROM flows
WHERE flows.hostname::text > t_1.hostname::text
ORDER BY flows.hostname
LIMIT 1) AS hostname
FROM t t_1
WHERE t_1.hostname IS NOT NULL
)
SELECT t.hostname
FROM t
WHERE t.hostname IS NOT NULL;