I'm actually very confused when performing postgresql stored procedure (I learned the below from somewhere):
create or replace procedure update_dba_trades ()
language plpgsql
as $$
begin
[CODE BLOCK WITH INSERT DELETE ETC...]
commit;
end;
$$
Why do we use all begin, end and commit? My understanding of postgresql is "end" is the same as "commit"
begin;
[code block]
end;
represents one complete transaction (either all failed or all succeed). I don't need to begin; [code]; commit; end;
However, I have difficulties trying to implement multiple independent code blocks. In PostgreSQL, I could do
begin;
[code block1]
end;
begin;
[code block2]
end;
Then [code block1] can succeed even if [code block 2] failed and wise versa. If I do,
create or replace procedure update_dba_trades ()
language plpgsql
as $$
begin;
[code block1]
end;
begin;
[code block2]
end;
$$
Then there is error. How do I achieve multiple independent code block? Thanks!
beginandendare just blocks in pl/pgsql. They have nothing to do with transactions.