postgresql array to rows
unnest( your_array )
postgres row expiration
CREATE TABLE expire_table (
timestamp timestamp NOT NULL DEFAULT NOW(),
name TEXT NOT NULL
);
INSERT INTO expire_table (name) VALUES ('a');
INSERT INTO expire_table (name) VALUES ('b');
INSERT INTO expire_table (name) VALUES ('c');
select * from expire_table;
timestamp | name
----------------------------+------
2014-09-26 15:33:43.243356 | a
2014-09-26 15:33:45.222202 | b
2014-09-26 15:33:47.347131 | c
(3 rows)
CREATE FUNCTION expire_table_delete_old_rows() RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
DELETE FROM expire_table WHERE timestamp < NOW() - INTERVAL '1 minute';
RETURN NEW;
END;
$$;
CREATE TRIGGER expire_table_delete_old_rows_trigger
AFTER INSERT ON expire_table
EXECUTE PROCEDURE expire_table_delete_old_rows();
INSERT INTO expire_table (name) VALUES ('d');
select * from expire_table;
timestamp | name
----------------------------+------
2014-09-26 15:36:56.132596 | d
(1 row)
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us