Re: Slow query to get last created row using CURRVAL

From: Віталій Тимчишин <tivv00(at)gmail(dot)com>
To: Mathieu De Zutter <mathieu(at)dezutter(dot)org>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: Slow query to get last created row using CURRVAL
Date: 2010-12-04 15:32:16
Message-ID: AANLkTinwFRuBMshSntDUiY_fwSiW7npTkHzt7owB=6Ta@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

2010/12/4 Mathieu De Zutter <mathieu(at)dezutter(dot)org>

>
> 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:

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') returning user_id;
--
Best regards,
Vitalii Tymchyshyn

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Tom Lane 2010-12-04 16:42:03 Re: Query-plan for partitioned UPDATE/DELETE slow and swaps vmem compared to SELECT
Previous Message Kevin Grittner 2010-12-04 15:29:06 Re: problem with from_collapse_limit and joined views