Sample Header Ad - 728x90

How to issue a DML with WHERE clause comparing a value which is trigger generated in table?

0 votes
1 answer
58 views
Suppose I have a table with CREATE, CREATE TABLE TEST ( year int, month int, date int, hr int, min int, sec int, timestamp timestamp, value double ); CREATE FUNCTION timestamp_insert() RETURNS trigger LANGUAGE plpgsql AS $$ DECLARE datestr TEXT ; DECLARE timestr TEXT ; begin datestr := new.year || '-' || new.month || '-' || new.date || ' ' || new.hour || ':' || new.min || ':' || new.sec;+ new.timestamp := datestr :: TIMESTAMP return new; end; $$ CREATE TRIGGER timestamp_insert BEFORE INSERT OR UPDATE ON TEST FOR EACH ROW EXECUTE PROCEDURE timestamp_insert(); Now I want to update a certain row based on the timestamp currently on the table and that from a new set of data. Something like, UPDATE TEST SET value = ? WHERE timestamp < "generated timestamp from a new set of (year, month, date, ...)" Is it possible to do something like this in SQL or do I need to programmatically genrate the timestamp and then simply pass that value in SQL?
Asked by Vineet Menon (185 rep)
Dec 13, 2019, 07:02 AM
Last activity: Dec 13, 2019, 07:23 AM