Question

I need a trigger to update a field with the exact date and time when the record is deleted. The fecha_validez_hasta field is TIMESTAMP WITHOUT TIME ZONE. I get a syntax error.

EXECUTE 'UPDATE '||TG_RELNAME||'_hv SET fecha_validez_hasta='||CURRENT_TIMESTAMP||' where id='||OLD.id;

enter image description here

The error is given in the beginning of the time section. It looks like it doesn't recognize it as a timestamp.

Was it helpful?

Solution

Your statement converts the value of CURRENT_TIMESTAMP into a string, which is not what you want.

Make the CURRENT_TIMESTAMP function call part of the real statement:

EXECUTE 'UPDATE '||TG_RELNAME||'_hv SET fecha_validez_hasta=CURRENT_TIMESTAMP where id='||OLD.id

Note fecha_validez_hasta=CURRENT_TIMESTAMP instead of fecha_validez_hasta='||CURRENT_TIMESTAMP||'..

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top