generate_series function on Redshift works as expected, when used in a simple select statement.
WITH series AS (
SELECT n as id from generate_series (-10, 0, 1) n
) SELECT * FROM series;
-- Works fine
As soon as I add a JOIN condition, redshift throws
com.amazon.support.exceptions.ErrorException: Function generate_series(integer,integer,integer)" not supported"
DROP TABLE testing;
CREATE TABLE testing (
id INT
);
WITH series AS (
SELECT n as id from generate_series (-10, 0, 1) n
) SELECT * FROM series S JOIN testing T ON S.id = T.id;
-- Function "generate_series(integer,integer,integer)" not supported.
Redshift Version
SELECT version();
-- PostgreSQL 8.0.2 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 3.4.2 20041017 (Red Hat 3.4.2-6.fc3), Redshift 1.0.1485
Are there any workarounds to make this work?
These PostgreSQL features are not supported in Amazon Redshift. Do not assume that the semantics of elements that Amazon Redshift and PostgreSQL have in common are identical.
Amazon Redshift is based on PostgreSQL which defaults on INNER JOIN same as many other query languages. select * from a JOIN b on a.a = b.b; Here 1,2 are unique to table A and 5,6 are unique to table B while 3,4 being common the query above returns only the values 3,4 so it's inner join.
In Redshift, when we need a sequence of dates between two given days, we can create it using the generate_series function and use it as a table in a FROM or JOIN clause. It is useful when we need to display a table of dates and values, but we don't have a value for each of those days.
The DUAL table is an actually existing physical table in the database that resides in the SYS schema. The table consists of a single column with the name “DUMMY”. The datatype of the column is VARCHAR2(1).
generate_series
is not supported by Redshift. It works only standalone on a leader node.
A workaround would be using row_number
against any table that has sufficient number of rows:
with
series as (
select (row_number() over ())-11 from some_table limit 10
) ...
also, this question was asked multiple times already
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With