Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

234
Visualizações
Create a PostgreSQL function from the command line

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?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Assuming your function is stored in a script file create_my_function.sql and you're to create it in database testdb owned by user testuser, here's one way to create it:

psql -h localhost -U testuser -d testdb -f create_my_function.sql

Not sure I understand your second question, but once the function is created it should be visible in any working db admin tool.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda