-
[PostgreSQL] Funkce
Ahoj, už delší dobu se morduju se zadaným úkolem, a to přepsat strukturu databáze z firebirdu do postgre. Jsou použity domény, funkce a všechny různé "kravinky" databázových serverů..
Problém mám s sql funkcema. Nevím, jak v postgre napsat jednoduchou funkci, která nic nevrátí, ale vloží řádek do tabulky pomocí INSERT..
Je tu někdo znalejší postgre, případně nemůžete mi doporučit nějaké fórum či jiný zdroj informací? dík.
-
Asi takto, hodim ti sem jednu funkci, nejsou tam INSERTy, ale to nevadi, je to stejny.
Kód:
create or replace function deleteParents()
returns void as
'
declare c1 RECORD;
begin
FOR c1 in select id from users where irole = -3
loop
update users set iParent1Users_id = null where iParent1Users_id = c1.id;
update users set iParent2Users_id = null where iParent2Users_id = c1.id;
update teachersbook set icheckusers_id = null where icheckusers_id = c1.id;
delete from LoginReport where iUsers_id = c1.id;
delete from users where id = c1.id;
end loop;
return;
end;
'
LANGUAGE 'plpgsql';
priklad volani :
select deleteParents();
Jako jiny zdroj informaci doporucuji www.builder.cz