Re: Slow query to get last created row using CURRVAL
От
Віталій Тимчишин
Тема
Re: Slow query to get last created row using CURRVAL
Дата
Msg-id
AANLkTinwFRuBMshSntDUiY_fwSiW7npTkHzt7owB=6Ta@mail.gmail.com
Ответ на
Slow query to get last created row using CURRVAL (Mathieu De Zutter)
Список
Дерево обсуждения
Slow query to get last created row using CURRVAL Mathieu De Zutter <mathieu@dezutter.org>
Re: Slow query to get last created row using CURRVAL Marti Raudsepp <marti@juffo.org>
Re: Slow query to get last created row using CURRVAL Mathieu De Zutter <mathieu@dezutter.org>
Re: Slow query to get last created row using CURRVAL Віталій Тимчишин <tivv00@gmail.com>
2010/12/4 Mathieu De Zutter <mathieu@dezutter.org>
INSERT INTO log_event (user_id, ip, action_id, object1_id, object2_id,
For each page load I first create an entry in that table, e.g.:
INSERT INTO log_event (user_id, ip, action_id, object1_id, object2_id,
event_timestamp, comments) VALUES (1, '127.0.0.1', 96, null, null,
NOW(), 'TEST');
After that, I want to retrieve the data stored in log_event from a
trigger, e.g.:
SELECT user_id FROM log_event WHERE id = CURRVAL('log_event_id_seq');
This way my insert-trigger knows who is creating the new row, while
using only one pg-user to query the database.
Please note that you can use next query to perform both insert and select:
event_timestamp, comments) VALUES (1, '127.0.0.1', 96, null, null,
NOW(), 'TEST') returning user_id;
--
Best regards,
Vitalii Tymchyshyn
В списке pgsql-performance по дате отправления
От: Tom Lane
Дата: