Начинаю только пользоваться этой субд, всегда юзал ms sql, подскажите, пожалуйста, как это триггер переписать на psql?
Голова уже кипит, хотелось бы помощи)
Спасибо заранее!
create trigger "checkExProd"
on "basket_products"
after insert
as
declare @productId integer, @basketId integer,
@weight integer, @price integer, @countItems integer,
@curCount integer,
@curPrice inreger,
select @productId = (select "productId" from inserted)
select @basketId = (select "basketId" from inserted )
select @weight = (select "weight" from inserted)
select @price = (select "price" from inserted)
select @countItems = (select "count" from inserted)
select @curCount = (select "count" from "basket_products"
where "basketId" = @basketId
and "productId" = @productId
and "weight" = @weight)
select @curPrice = (select "price" from "basket_products"
where "basketId" = @basketId
and "productId" = @productId
and "weight" = @weight)
begin
if( (select count(*) from
"basket_products"
where "productId" = @productId
and "basketId" = @basketId
and "weight" = @weight) > 1 )
begin
update "basket_products"
set "count" = @curCount + @countItems,
"price" = @curPrice + @price
where "basketId" = @basketId
and "productId" = @productId
and "weight" = @weight
end
end