Postgresql - Automatic date return from another data field

Asked

Viewed 17 times

0

good afternoon!

I’m trying to create a Rigger that returns the automatic date from another date field. Type insert in one field this date and in the other return 730 days ahead. In this case, I have three date fields to be considered. 1 - An initial date; 2 - Renewal date; 3 - Next renewal date. When the first date record occurs the field 3 is based on field 1 and when there is the first, second, third... renewals, field 3 ceases to consider 1 and is based on field 2. So I want to build a Rigger that does the automatic calculation. I’m trying the following:

CREATE FUNCTION duep.proxima_data_renovacao()
RETURNS trigger
LANGUAGE 'plpgsql'
COST 100
VOLATILE NOT LEAKPROOF
AS $BODY$
BEGIN
    --
    -- Create a update in parklet.data_renovacao_termo_definitivo to reflect the operation performed    on emp,
    -- making use of the special variable TG_OP to work out the operation.
    --
    SELECT data_emissao_termo_definitivo, data_renovacao_termo_definitivo, data_proxima_renovacao_termo_definitivo
    FROM duep.parklet;
    IF (duep.data_renovacao_termo_definitivo IS NULL) 
    THEN return duep.data_proxima_renovacao_termo_definitovo = duep.data_emissao_termo_definitivo + 730;
    ELSIF (duep.data_renovacao_termo_definitivo IS NOT NULL) 
    THEN return duep.data_proxima_renovacao_termo_definitovo = duep.data_renovacao_termo_definitivo + 730;
    ELSE NULL;
    END IF;

    RETURN NULL; -- result is ignored since this is an AFTER trigger
END;
$BODY$;

However when trying to change the record in the table an error appears: If you want to discard results from a SELECT, use PERFORM. Good, I would like a help to find the best solution!

Thank you very much!

No answers

Browser other questions tagged

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