Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can't use JOIN with generate_series on Redshift

Tags:

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?

like image 512
Rahul Avatar asked Oct 16 '17 22:10

Rahul


People also ask

Which of the following feature is not supported in AWS redshift?

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.

What is the default join in redshift?

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.

How do you create a series of dates in redshift?

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.

What is the dual table in redshift?

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).


1 Answers

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

like image 89
AlexYes Avatar answered Sep 22 '22 00:09

AlexYes