У меня есть следующий sql на сервере SQL
declare @groupName varchar(50)
select @groupName=groupIdentifier from tab1 where col3 ='ABC'
if @groupName is not NULL
select @groupName
return
select @groupName=col2 from tab2 where col1= 'BCD'
if @groupName is not NULL
select @groupName
return
Я перевел на RedShift следующим образом:
create temp table t1
(groupName)
---- Statement 1 -----
insert into t1 select groupIdentifier from tab1 where col3 ='ABC'
---- Statement 2 -----
insert into t1 select col2 from tab2 where col1= 'BCD' and (select count(1) from t1)=0
select * from t1
Поскольку в RedShift нет оператора return, Оператор 2 всегда выполняется, даже когда Оператор 1 смог извлечь строку. Поскольку второе утверждение стоит дорого, как эффективно предотвратить его выполнение, если утверждение 1 выполнено успешно.