Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

231
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda