Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can if-then-else logic be done in Redshift?

I am a newbie to RedShift but experienced with MSSQL. I was wondering if there's any way to write an if-then-else logic in Redshift?

Basically I want to run this logic in Redshift:

if ((select count(*) from a) - (select count(*) from b)) = 0 then 
   drop table a;

Thanks in advance!

like image 222
user3823907 Avatar asked Feb 02 '26 13:02

user3823907


1 Answers

Redshift doesn't support procedural statements, so you handle this best in your application code. If you must do it inside of SQL, something along the lines of this may help:

delete from a where (select count(*) from a) = (select count(*) from b);

This doesn't drop the table but deletes all rows from it when your condition is met.

like image 192
user2303197 Avatar answered Feb 05 '26 03:02

user2303197