pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Scott Marlowe <scott.marlowe@gmail.com>
To: Rob Sargent <robjsargent@gmail.com>
Cc: Osvaldo Kussama <osvaldo.kussama@gmail.com>
Cc: m_qoreishy@yahoo.com
Cc: pgsql-sql@postgresql.org
Subject: Re: reading last inserted record withoud any autoincrement field
Date: Mon, 5 Oct 2009 16:23:28 -0600
Message-ID: <dcc563d10910051523x59de62c6he5cdd8d567845c10@mail.gmail.com> (raw)
In-Reply-To: <4AC8F8BC.2050905@gmail.com>
References: <444951.51198.qm@web33806.mail.mud.yahoo.com>
	<690707f60910041137l340d2873le86d8f3458188471@mail.gmail.com>
	<4AC8F8BC.2050905@gmail.com>

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.



view thread (4+ messages)

Message-ID: <dcc563d10910051523x59de62c6he5cdd8d567845c10@mail.gmail.com>
Permalink:  ../dcc563d10910051523x59de62c6he5cdd8d567845c10@mail.gmail.com/
Also on:    postgresql.org/message-id/dcc563d10910051523x59de62c6he5cdd8d567845c10@mail.gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: scott.marlowe@gmail.com, robjsargent@gmail.com, osvaldo.kussama@gmail.com, m_qoreishy@yahoo.com
  Subject: Re: reading last inserted record withoud any autoincrement field
  In-Reply-To: <dcc563d10910051523x59de62c6he5cdd8d567845c10@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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