Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id B05A66343AE for ; Sun, 4 Oct 2009 16:34:34 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 42660-05 for ; Sun, 4 Oct 2009 19:34:27 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-qy0-f195.google.com (mail-qy0-f195.google.com [209.85.221.195]) by mail.postgresql.org (Postfix) with ESMTP id F406763421B for ; Sun, 4 Oct 2009 16:34:26 -0300 (ADT) Received: by qyk33 with SMTP id 33so2705904qyk.29 for ; Sun, 04 Oct 2009 12:34:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:cc:subject:references:in-reply-to :content-type:content-transfer-encoding; bh=/+ikaD/UA1/QY5wimq2mASRiIHUJ/IqWMWrLDExHBf4=; b=NlLscjz/Un95iS0ERSCZxbRT8vxkJpLF9bZTXxl96/JKU0uX3rXSkJrORXllqB1+qr rdKLc23p/A1SynFagMrZqXo3wl4AohJ6lSjPOql3pKq0CibxowBNcV0yB6B7GivPWEoJ 95Z65awjeA7MvOWnIlz4a76BNj+zcAM6yyAOo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; b=cTrjacHteYMezQrVYZlkn2l4LMHUioQ/LP3yMA5zxqxf2e9pT1pVaJOHY/v8Fow0aQ NUAcFuEbeOR4fAuRpwDxMPJIIWFZjFrLGMKitS5jy5mU5MGeB/VKPoN9K4sc0iOWREYV Az/AcU9+75KElr82wlmIE/gWa8mEBI8V34ZIc= Received: by 10.224.83.136 with SMTP id f8mr2664931qal.86.1254684865768; Sun, 04 Oct 2009 12:34:25 -0700 (PDT) Received: from ?192.168.0.2? (rsargent.dsl.xmission.com [199.104.125.126]) by mx.google.com with ESMTPS id 2sm302768qwi.25.2009.10.04.12.34.22 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sun, 04 Oct 2009 12:34:24 -0700 (PDT) Message-ID: <4AC8F8BC.2050905@gmail.com> Date: Sun, 04 Oct 2009 13:34:20 -0600 From: Rob Sargent User-Agent: Thunderbird 2.0.0.23 (X11/20090817) MIME-Version: 1.0 To: Osvaldo Kussama CC: m_qoreishy@yahoo.com, pgsql-sql@postgresql.org Subject: Re: reading last inserted record withoud any autoincrement field References: <444951.51198.qm@web33806.mail.mud.yahoo.com> <690707f60910041137l340d2873le86d8f3458188471@mail.gmail.com> In-Reply-To: <690707f60910041137l340d2873le86d8f3458188471@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.599 tagged_above=-10 required=5 tests=BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 200910/22 X-Sequence-Number: 33221 Osvaldo Kussama wrote: > 2009/10/4 mohammad qoreishy > >> 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.