Postgres Pl syntax (syntax error at or near "integer")

Asked

Viewed 233 times

0

I’m having trouble making a Pl in Postgres, I don’t know where I’m going wrong, can help me...

THE TENACIOUS:

do $$
declare

    id_cir integer;

begin

    -- ERROR: syntax error at or near "integer"
    (SELECT ES.ID FROM demo.public.corp_especialidade_saude ES WHERE ES.NOME LIKE '%CIRURGIA%') into id_cir;

    -- ERROR: syntax error at or near "integer"
    SELECT ES.ID into id_cir FROM demo.public.corp_especialidade_saude ES WHERE ES.NOME LIKE '%CIRURGIA%';

    -- ERROR: syntax error at or near "integer"
    id_cir := (SELECT ES.ID FROM demo.public.corp_especialidade_saude ES WHERE ES.NOME LIKE '%CIRURGIA%');

    INSERT INTO demo.public.corp_sub_especialidade_saude (ID, ID_ESPECIALIDADE_SAUDE, NOME)
    VALUES (
            (SELECT SUM(S.ID+1) FROM demo.public.corp_sub_especialidade_saude S WHERE S.ID = (select max(ID) from demo.public.corp_sub_especialidade_saude)),
            id_cir, 
            'CIRURGIA TESTE'
            );

END $$;

RESOLVED:

do $$
    declare
        id_cir integer;
    begin
        SELECT ES.ID into id_cir FROM demo.public.corp_especialidade_saude ES WHERE ES.NOME LIKE '%CIRURGIA%';
        INSERT INTO demo.public.corp_sub_especialidade_saude (ID, ID_ESPECIALIDADE_SAUDE, NOME)
        VALUES (
                   (SELECT SUM(S.ID+1) FROM demo.public.corp_sub_especialidade_saude S WHERE S.ID = (select max(ID) from demo.public.corp_sub_especialidade_saude)),
                   id_cir,
                   'CIRURGIA TESTE'
               );
    END $$;

IDEA was not running the DECLARE only line down, for a lack of attention from me!

  • Does your code actually have these 3 Selects? What do you want with SUM(S.ID+1)?

  • I don’t understand a word of your attempt at explanation.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.