Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error in query to Redshift

I need to count the number of users in every month. I have written query.

SELECT COUNT(distinct user_id) 
from (
select TO_CHAR((current_date - interval '1 month' * a),'YYYY-MM') as MyMonth
from generate_series(1,60,1) AS s(a)
) months 
 LEFT OUTER JOIN database.users
ON months.MyMonth=to_char(created_at, 'YYYY-MM')
GROUP BY months.MyMonth

But when I try to execute it, the mistake appears: "Specified types or functions (one per INFO message) not supported on Redshift tables." Whether it is possible to rewrite somehow this query or specify please where a mistake?

like image 428
Kirill Avatar asked Feb 07 '17 23:02

Kirill


People also ask

Why was my query aborted redshift?

A query can abort in Amazon Redshift for the following reasons: Setup of Amazon Redshift workload management (WLM) query monitoring rules. Statement timeout value. ABORT, CANCEL, or TERMINATE requests.

Does redshift support SQL queries?

Amazon Redshift supports SQL client tools connecting through Java Database Connectivity (JDBC) and Open Database Connectivity (ODBC). Amazon Redshift doesn't provide or install any SQL client tools or libraries, so you must install them on your client computer or Amazon EC2 instance to use them.

Why is my redshift query taking so long?

Load takes too long Your load operation can take too long for the following reasons; we suggest the following troubleshooting approaches. Split your load data into multiple files. When you load all the data from a single large file, Amazon Redshift is forced to perform a serialized load, which is much slower.

What is redshift spectrum scan error?

This error usually indicates some problem with compatibility of data in your file and redshift tables. you can get more insights about error in table 'SVL_S3LOG'. In my case it was because file had some invalid utf8 characters.


1 Answers

The generate_series() command is not fully supported on Amazon Redshift.

It can be used for queries that run solely on the Leader node, but cannot be used in queries that involve tables because they involve cluster nodes. The only workaround is to create a large table with lots of values and join to it to get a range of numbers. (A bit of work up front, but then it works fine.)

You'll find many similar Questions on StackOverflow related to generate_series().

like image 176
John Rotenstein Avatar answered Sep 22 '22 11:09

John Rotenstein