Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save yogonza524/93e3f800dc3d30ea74d9 to your computer and use it in GitHub Desktop.
Save yogonza524/93e3f800dc3d30ea74d9 to your computer and use it in GitHub Desktop.
-- Function: public.update_config()
-- DROP FUNCTION public.update_config();
CREATE OR REPLACE FUNCTION public.update_config()
RETURNS trigger AS
$BODY$
DECLARE
output integer;
BEGIN
IF (NEW.dia_emision < 1 OR NEW.dia_emision > 31) THEN
NEW.dia_emision = 1;
END IF;
IF (NEW.dia_vencimiento < 1 OR NEW.dia_vencimiento > 31) THEN
NEW.dia_vencimiento = 15;
END IF;
IF (NEW.id <> OLD.id) THEN
NEW.id = OLD.id;
END IF;
NEW.fecha_ultima_modificacion = now();
RETURN NEW;
END;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
ALTER FUNCTION public.update_config()
OWNER TO postgres;
@yogonza524
Copy link
Author

La clave generada es unica y no se puede modificar, si se quiere hacerlo se vuelve siempre al valor anterior (generado solo por el trigger)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment