Skip to content
Advertisement

Tag: amazon-redshift

Convert character to number, like +00005 to 5

We have the fixed format data and it has the number with plus/minus sign, like +00005 or -00005. We’d like to convert it to number but Redshift seems not to allow implicit conversion. So, I temporarily use to_number(replace(<numbercolumn>, ‘+’, ”),’99999′) But I guess there should be more better solutions. Anyone know more smart way, your advice would be highly appreciated.

Can’t alter column type to a shorter VARCHAR in Redshift. Getting “target column size should be greater or equal to current maximum column size”

I’m trying to run in Amazon Redshift, but I’m getting this error: SQL Error [500310] [0A000]: Amazon Invalid operation: cannot alter column “column_name” of relation “table_name”, target column size 256 should be greater or equal to current maximum column size 879; I’ve already tried and in order to reduce this maximum column size of 879, but I still get the

Creating date segments in redshift SQL

I’m trying to create segments of date based on a flag. Below is the table I currently have order by start_date,end_date. ID start_date end_date flag 9659 5/18/2012 5/18/2012 0 9659 5/18/2012 5/18/2012 0 9659 6/8/2012 6/8/2012 0 9659 6/8/2012 6/8/2012 0 9659 8/25/2012 8/25/2012 1 9659 8/27/2012 8/27/2012 0 9659 10/27/2012 10/27/2012 1 I’d like to create a column named

addition within sum case when

How to sum all the customers in DS01,02,03 into DS? select sum(case when Ticket=’DS01′ OR ‘DSO2’ OR ‘DS03′ THEN customer ELSE 0 END) AS DS sum(case when Ticket=’MSO2’ OR ‘MS03’ THEN customer ELSE 0 END) AS MS from table group by ticket unsure how to bring in addition condition within “THEN and ELSE ” part Answer You can use left():

Syntax error for nested condtionals in SQL

I’m pretty new to redshift and I’ve been trying to to do a nested case when condition here, yet I get a syntax error ERROR: syntax error at or near “)” in this line of SQL: I’m not sure what’s wrong, since I’m familiar with Python and I’m pretty sure this is how nested conditions work Answer You should end

RANK data by value in the column

I’d like to divide the data into separate groups (chunks) based on the value in the column. If the value increase above certain threshold, the value in the “group” should increase by 1. This would be easy to achieve in MySQL, by doing CASE WHEN @val > 30 THEN @row_no + 1 ELSE @row_no END however I am using Amazon

Advertisement