Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5f66201

Browse files
Corrige triggers
1 parent 6e23834 commit 5f66201

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

‎dados.sql

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,23 +126,29 @@ create table item_venda(
126126
CREATE OR REPLACE FUNCTION diminui_estoque_func()
127127
RETURNS trigger AS $$
128128
BEGIN
129-
update produto set estoque = estoque - new.quant where produto.id = new.produto_id;
129+
update estoque set quant = quant - new.quant
130+
where produto_id = new.produto_id
131+
and estoque.loja_id = (select v.loja_id from venda v where v.id = new.venda_id);
130132
RETURN NEW;
131133
END;
132134
$$ LANGUAGE 'plpgsql';
133135

134136
CREATE OR REPLACE FUNCTION devolve_estoque_func()
135137
RETURNS trigger AS $$
136138
BEGIN
137-
update produto set estoque = estoque + old.quant where produto.id = old.produto_id;
139+
update estoque set quant = quant + old.quant
140+
where produto_id = old.produto_id
141+
and estoque.loja_id = (select v.loja_id from venda v where v.id = old.venda_id);
138142
RETURN NEW;
139143
END;
140144
$$ LANGUAGE 'plpgsql';
141145

142146
CREATE OR REPLACE FUNCTION atualiza_estoque_func()
143147
RETURNS trigger AS $$
144148
BEGIN
145-
update produto set estoque = estoque + old.quant - new.quant where produto.id = new.produto_id;
149+
update estoque set quant = quant + old.quant - new.quant
150+
where produto_id = new.produto_id
151+
and loja_id = (select v.loja_id from venda v where v.id = new.venda_id);
146152
RETURN NEW;
147153
END;
148154
$$ LANGUAGE 'plpgsql';

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /