pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
reading last inserted record withoud any autoincrement field
4+ messages / 4 participants
[nested] [flat]

* reading last inserted record withoud any autoincrement field
@ 2009-10-04 14:49  mohammad qoreishy <m_qoreishy@yahoo.com>
  0 siblings, 1 reply; 4+ messages in thread

From: mohammad qoreishy @ 2009-10-04 14:49 UTC (permalink / raw)
  To: pgsql-sql

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.



      

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: reading last inserted record withoud any autoincrement field
@ 2009-10-04 18:37  Osvaldo Kussama <osvaldo.kussama@gmail.com>
  parent: mohammad qoreishy <m_qoreishy@yahoo.com>
  0 siblings, 1 reply; 4+ messages in thread

From: Osvaldo Kussama @ 2009-10-04 18:37 UTC (permalink / raw)
  To: m_qoreishy@yahoo.com; +Cc: pgsql-sql

2009/10/4 mohammad qoreishy <m_qoreishy@yahoo.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



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: reading last inserted record withoud any autoincrement field
@ 2009-10-04 19:34  Rob Sargent <robjsargent@gmail.com>
  parent: Osvaldo Kussama <osvaldo.kussama@gmail.com>
  0 siblings, 1 reply; 4+ messages in thread

From: Rob Sargent @ 2009-10-04 19:34 UTC (permalink / raw)
  To: Osvaldo Kussama <osvaldo.kussama@gmail.com>; +Cc: m_qoreishy@yahoo.com; pgsql-sql

Osvaldo Kussama wrote:
> 2009/10/4 mohammad qoreishy <m_qoreishy@yahoo.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.



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: reading last inserted record withoud any autoincrement field
@ 2009-10-05 22:23  Scott Marlowe <scott.marlowe@gmail.com>
  parent: Rob Sargent <robjsargent@gmail.com>
  0 siblings, 0 replies; 4+ messages in thread

From: Scott Marlowe @ 2009-10-05 22:23 UTC (permalink / raw)
  To: Rob Sargent <robjsargent@gmail.com>; +Cc: Osvaldo Kussama <osvaldo.kussama@gmail.com>; m_qoreishy@yahoo.com; pgsql-sql

On Sun, Oct 4, 2009 at 1:34 PM, Rob Sargent <robjsargent@gmail.com> wrote:
> Osvaldo Kussama wrote:
>>
>> 2009/10/4 mohammad qoreishy <m_qoreishy@yahoo.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.

Given that he's mentioning cursors, I'm guessing he's talking about
during this session / transaction.  So returning would be best.  Note
that returning returns a SET of results, so that if your insert
inserts 10 rows, you'll get back 10 rows from returning.



^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2009-10-05 22:23 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2009-10-04 14:49 reading last inserted record withoud any autoincrement field mohammad qoreishy <m_qoreishy@yahoo.com>
2009-10-04 18:37 ` Osvaldo Kussama <osvaldo.kussama@gmail.com>
2009-10-04 19:34   ` Rob Sargent <robjsargent@gmail.com>
2009-10-05 22:23     ` Scott Marlowe <scott.marlowe@gmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox