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

203
Visualizações
Execute a query for every row of a table inside a trigger function

I have made the following query which is working perfect by itself but when i call it inside trigger function i got problem.

select insert_new_grade('title0', return3_6(0), return3_6(1), return3_6(2), s.code)
FROM "student" as s
where find_st(s.grade)>=5;

insert_new_grade is a function that inserts a new row in a table every time it's being called.

Here is the trigger :

CREATE OR REPLACE FUNCTION insert_d() 
RETURNS TRIGGER AS $$ 
BEGIN
    select insert_new_grade('title0', return3_6(0), return3_6(1), return3_6(2), s.code)
    FROM "student" as s
    where find_st(s.grade)>=5;

    return new;
END;
$$ LANGUAGE plpgsql; 

and here is the insert function :

CREATE OR REPLACE FUNCTION insert_new_grade(title0 character(100), prof0 character(11), prof1 character(11)) 
RETURNS VOID AS $$
BEGIN
    INSERT INTO "d_table"(thes0, title, grade, prof, secProf) 
    VALUES (null, title0, null, prof0, prof1);
END
$$
LANGUAGE 'plpgsql';

Is there a way to make the query work inside the trigger function ? If i use perform instead of select the insert function does not have result. I've read about cursors but I'm new in postgresql and I don't know how to do it. Any help ?

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

0

i modifited your trigger function:

check your trigger function in conlose pgAdmin, is visible raise info text

CREATE OR REPLACE FUNCTION insert_d() 
RETURNS TRIGGER AS $$ 
declare
    rec record;
BEGIN

    for rec in (select * from student s where find_st(s.grade)>=5) loop

        raise info 'LOOP code = %',rec.code;
        PERFORM insert_new_grade('title0', return3_6(0), return3_6(1), return3_6(2), rec.code);

    end loop;

    return new;
END;
$$ LANGUAGE plpgsql; 
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