The generate_series function does not work on Redshift
it does however generate_confusion! This is because it looks like its working fine until you try to write to a table.
Technically, the reason for this is that it works ONLY on the leader node. and the leader node itself does not have access to the tables directly.
If you try
SELECT CURRENT_DATE::TIMESTAMP - (i * interval '1 day') as date_datetime
FROM generate_series(1,31) i
ORDER BY 1;
That produces a nice table output, because it has run on the leader node.
HOWEVER
if you run
create table test as
SELECT CURRENT_DATE::TIMESTAMP - (i * interval '1 day') as date_datetime
FROM generate_series(1,31) i
ORDER BY 1;
This fails with
[2019-03-11 07:38:00] [0A000] ERROR: Specified types or functions (one
per INFO message) not supported on Redshift tables. [2019-03-11
07:38:00] [00000] Function "generate_series(integer,integer)" not
supported.
This is because we are now trying to create a table, so the sql has to be run on the worker nodes (not the leader node) and so it fails.