There are many answers to this question h e r e already (those 4 are all this month).
But major point to note is you MUST NOT use SEQx()
as the number generator (you can use it in the ORDER BY, but that is not needed). As noted in the doc's
Important
This function uses sequences to produce a unique set of increasing integers, but does not necessarily produce a gap-free sequence. When operating on a large quantity of data, gaps can appear in a sequence. If a fully ordered, gap-free sequence is required, consider using the ROW_NUMBER window function.
CREATE TABLE table_of_2_years_date_times AS
SELECT
date_time::date as date,
date_time::time as time
FROM (
SELECT
row_number() over (order by null)-1 as rn
,dateadd('minute', 15 * rn, '2022-03-01'::date) as date_time
from table(generator(rowcount=>4*24*365*2))
)
ORDER BY rn;
then selecting the top/bottom:
(SELECT * FROM table_of_2_years_date_times ORDER BY date,time LIMIT 5)
UNION ALL
(SELECT * FROM table_of_2_years_date_times ORDER BY date desc,time desc LIMIT 5)
ORDER BY 1,2;
DATE |
TIME |
2022-03-01 |
00:00:00 |
2022-03-01 |
00:15:00 |
2022-03-01 |
00:30:00 |
2022-03-01 |
00:45:00 |
2022-03-01 |
01:00:00 |
2024-02-28 |
22:45:00 |
2024-02-28 |
23:00:00 |
2024-02-28 |
23:15:00 |
2024-02-28 |
23:30:00 |
2024-02-28 |
23:45:00 |