When I run the SQL Query:
select generate_series(0,g)
from ( select date(date1) - date(date2) as g from mytable ;
It returns an error:
You are not using PostgreSQL. You are using Amazon Redshift.
Amazon Redshift does not support generate_series when used with Redshift tables. It says it right there in the error message.
Either use real PostgreSQL, or if you need Redshift's features, you must also work within the limitations of Redshift.
Your second example works because it does not use any Redshift tables.