I'm trying to create a function that allows me to perform multiple Queries in my database. It's the first time that I try to use the command line for this objective. I'm working in a linux system (Ubuntu), using the PostgreSQL.
My Pgsql:
create function my_function(idteste integer, nome character varying, tipo integer, morada character varying, cpostal character varying, telefone character varying, nif character varying, nacionalidade character varying, iban character varying, moradaimag character varying, cc1 character varying, ccimage1 character varying, ccimage2 character varying, datanascimento date)
returns character varying as $tempvar$
declare tempvar character varying;
begin
tempvar := 'null';
if (select count(id_teste) from singulares where id_idteste=idteste) = 0 then
update pessoas set
nome_pessoal=nome,
tipo_pesoal = tipo,
morada_pessoal=morada,
cpostal_pessoal=cpostal,
telefone_pessoal=telefone,
nif_pessoal=nif,
nacionalidade_pessoal=nacionalidade,
iban_pessoal=iban,
cmorada_img=cmoradaimag
where
id_teste=idteste;
insert into singulares (pessoas_idteste, cc, cc_img1, cc_img2, data_nascimento) values(idteste, cc1, ccimage1, ccimage2, datanascimento);
tempvar := 'gravado com sucesso';
else
update pessoas set
nome_pessoal=nome,
tipo_pesoal = tipo,
morada_pessoal=morada,
cpostal_pessoal=cpostal,
telefone_pessoal=telefone,
nif_pessoal=nif,
nacionalidade_pessoal=nacionalidade,
iban_pessoal=iban,
cmorada_img=cmoradaimag
where
id_teste=idteste;
update singulares set
cc=cc1,
cc_img1=ccimage1,
cc_img2=ccimage2
where
pessoas_idteste=idteste;
tempvar := 'alterado com sucesso';
end if;
return tempvar;
end
$tempvar$ language plpgsql;
My first question is how can I create the function through the command line?
Second question when creating the function, will this be visible from PGmyadmin?