Re: reading last inserted record withoud any autoincrement field

From: Rob Sargent <robjsargent(at)gmail(dot)com>
To: Osvaldo Kussama <osvaldo(dot)kussama(at)gmail(dot)com>
Cc: m_qoreishy(at)yahoo(dot)com, pgsql-sql(at)postgresql(dot)org
Subject: Re: reading last inserted record withoud any autoincrement field
Date: 2009-10-04 19:34:20
Message-ID: 4AC8F8BC.2050905@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Osvaldo Kussama wrote:
> 2009/10/4 mohammad qoreishy <m_qoreishy(at)yahoo(dot)com>
>
>> How can get last inserted record in a table without any autoincrement filed?
>> I need to frequently fetch the last inserted record.
>> If I must use the "Cursor" please explain your solution.
>>
>>
>
>
> RETURNING clause?
> http://www.postgresql.org/docs/current/interactive/sql-insert.html
>
> Osvaldo
>
>
It took the OP to mean last insert as in randomly in the past, not as
part of current transaction. My fear is OP's schema has no way of
identifying time-of-insert, nor a monotonically increasing record id and
is hoping postgres has a some internal value that will return the most
recently inserted record. Without a table definition it's hard to say.

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Lew 2009-10-05 00:44:27 Re: Common table expression - parsing questions
Previous Message Osvaldo Kussama 2009-10-04 18:37:40 Re: reading last inserted record withoud any autoincrement field