From m_qoreishy@yahoo.com Sun Oct 4 14:50:03 2009 Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id E713F632E94 for ; Sun, 4 Oct 2009 11:50:03 -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 12387-05 for ; Sun, 4 Oct 2009 14:49:56 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from web33806.mail.mud.yahoo.com (web33806.mail.mud.yahoo.com [209.191.69.169]) by mail.postgresql.org (Postfix) with SMTP id 4F4FF632CCD for ; Sun, 4 Oct 2009 11:49:56 -0300 (ADT) Received: (qmail 51208 invoked by uid 60001); 4 Oct 2009 14:49:54 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1254667794; bh=DJqJ3OdNdN0pobYwzlSARDUsTr9OtiUZArTmfzLZ1AM=; h=Message-ID:X-YMail-OSG:Received:X-Mailer:Date:From:Reply-To:Subject:To:MIME-Version:Content-Type; b=kCPLsW/eB6m55q/Ai+3ptNFUEp+nasOa7YXC9+cYkvuWq0YKe7K//xmYaVkUFdCpzHe2kOvge+fW82DZgTgTzzSoUyc9dEoewuTwJkn6Fo1H8ntSLuW/r3Q7w4ZYpAUansxVdRX1gzYJ0OALVntFpkwITI9vJTVU9wAtv4ly3QI= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:X-YMail-OSG:Received:X-Mailer:Date:From:Reply-To:Subject:To:MIME-Version:Content-Type; b=AdVkOdwINKL7Yrilxx5jBsa94orqFpBNoKHdcTAs8WoYWAB4JOIShmsiWLkxKM0LcIW7kRtSFqYnXMzj/OL9haiKpK2phCv3Kbc+3zpXBruMdxZHiZAfBbyubnVdp4FnOuD1POyaGK6zftzt+qT3GJ8gTJWLs0jvxlYxfCMPvHU=; Message-ID: <444951.51198.qm@web33806.mail.mud.yahoo.com> X-YMail-OSG: 5Xjuj9MVM1lssjZB1w6.VynVHensbFFj0E2mmCAW3V0Zwr7Do8PfsZxPFKKJ5T_cH_S0gHcP0nTLxfS9QQz5VftUG9M3lMzKg3WttGCOpS3J85Rdp6TKefPFIVzGcnyU9VVI55pjkmY8vJX.4FItp.3KtOxIDOH6XhaVeM.nYJ4mGcn_fzxpSabmTRgto5_K2TjfNDURXl0H7qQceZKJ6HQ440NMst_uGaL7UwTsPNRVYkCY6lEqdK_p7XP4kJxW8HKswU0yyZrPdWfk7.vv_9.YMTep59GPRcNjwYRqXFMlinSN4EmdurqiM3lAK6lYnO9tgpndplugdqLTGlT8xO2bdKddEbuj7kqd94s8RUuzyg5LFqyv2y5bquJw6qx_yzJ7pxmFdLtrQoE7mQFLOg-- Received: from [213.176.95.42] by web33806.mail.mud.yahoo.com via HTTP; Sun, 04 Oct 2009 07:49:54 PDT X-Mailer: YahooMailClassic/7.0.14 YahooMailWebService/0.7.347.3 Date: Sun, 4 Oct 2009 07:49:54 -0700 (PDT) From: mohammad qoreishy Reply-To: m_qoreishy@yahoo.com Subject: reading last inserted record withoud any autoincrement field To: pgsql-sql@postgresql.org MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="0-972658667-1254667794=:51198" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.002 tagged_above=-10 required=5 tests=BAYES_50=0.001, HTML_MESSAGE=0.001 X-Spam-Level: X-Archive-Number: 200910/19 X-Sequence-Number: 33218 --0-972658667-1254667794=:51198 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable How can get last inserted record in a table without any autoincrement filed= ? I need to=A0 frequently fetch the last inserted record. If I must use the "Cursor" please explain your solution. =0A=0A=0A --0-972658667-1254667794=:51198 Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable
How can get last inserted record in a table w= ithout any autoincrement filed?
I need to  frequently fetch the las= t inserted record.
If I must use the "Cursor" please explain your soluti= on.

=0A=0A --0-972658667-1254667794=:51198-- From osvaldo.kussama@gmail.com Sun Oct 4 18:37:51 2009 Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 75BC1632F4C for ; Sun, 4 Oct 2009 15:37:51 -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 36874-10 for ; Sun, 4 Oct 2009 18:37:43 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-bw0-f227.google.com (mail-bw0-f227.google.com [209.85.218.227]) by mail.postgresql.org (Postfix) with ESMTP id 1C202632CCD for ; Sun, 4 Oct 2009 15:37:42 -0300 (ADT) Received: by bwz27 with SMTP id 27so2010002bwz.19 for ; Sun, 04 Oct 2009 11:37:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=LOclyp2bkmcJLS+oL/Mh8WfNHVthTP8ms0FjJx26K30=; b=uzMUZBFj6ovogurK7VS4HtWs8G8YQ1BLlWuRBVstam0bt7hlW2G9+85CBeTQYR975h dQHqtgtksJCr3lGZbG5GWmY4ikhCo/F0ycs1U+kuOzqvyhsd4/OTGkeBIRk/hc0T+00w RqKDfYRJoWrzNfhS37IfHPF7CUzbPx01cm/7o= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=IIPFLmAcxzVgNnTuuGNa20O/A2leb0YeyOItIRuc9WanD2MVxl8TKtuIHI451cFqJz ZfmwVmqAiQ23XW5ZNnyMuqj/0s22f5Gw6lNX02hNP+5R7wITwOxzY2EQYPkupH9Av/t+ OuMgQmX4fsWVzUSRZr+GrF7Acj43HimlkZAhM= MIME-Version: 1.0 Received: by 10.239.141.131 with SMTP id c3mr504177hba.44.1254681460546; Sun, 04 Oct 2009 11:37:40 -0700 (PDT) In-Reply-To: <444951.51198.qm@web33806.mail.mud.yahoo.com> References: <444951.51198.qm@web33806.mail.mud.yahoo.com> Date: Sun, 4 Oct 2009 15:37:40 -0300 Message-ID: <690707f60910041137l340d2873le86d8f3458188471@mail.gmail.com> Subject: Re: reading last inserted record withoud any autoincrement field From: Osvaldo Kussama To: m_qoreishy@yahoo.com Cc: pgsql-sql@postgresql.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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/21 X-Sequence-Number: 33220 2009/10/4 mohammad qoreishy > > How can get last inserted record in a table without any autoincrement fil= ed? > I need to=A0 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 From robjsargent@gmail.com Sun Oct 4 19:34:34 2009 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. From scott.marlowe@gmail.com Mon Oct 5 22:23:40 2009 Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id BBF1F633B75 for ; Mon, 5 Oct 2009 19:23:40 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 67665-08 for ; Mon, 5 Oct 2009 22:23:24 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-iw0-f182.google.com (mail-iw0-f182.google.com [209.85.223.182]) by mail.postgresql.org (Postfix) with ESMTP id E63B96334C1 for ; Mon, 5 Oct 2009 19:23:29 -0300 (ADT) Received: by iwn12 with SMTP id 12so1684496iwn.15 for ; Mon, 05 Oct 2009 15:23:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=wRSaJZLUSRW8Vndlod7OnGrBNAe/va376M+7QjD/dGk=; b=C/ScoP9X/bziyENYSynfPyNX/WMINbVnVHubcX/ZyEbTtY+NPG/tyK+x4LbqOQHz5O e8pYTR/nVk9xa8t3HBrUnTkkspBC8zXcDRreroNCMnXoIXx3c9/ClhCk+aK/6nwdjCX/ rLTmw1bh/vWEsEK63+Z/7OYL4KLj8kP9jegkA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=xpHruHMJnWQDpIKm6RzGgKzSRI//fyBqx5aQXYO3pvliQv5Zb/M04h5k8KNMfZPfGs 5WRZGiVXtJYWtpFMfhfyeHbpsHFiUcrI3MgtWPwFI5zDIoFftRum176NPS1ZJagcrIFl AFm0Gs4JtwIbcyExWY73RA+OcNcAr3X5USevY= MIME-Version: 1.0 Received: by 10.231.83.75 with SMTP id e11mr1091859ibl.11.1254781408287; Mon, 05 Oct 2009 15:23:28 -0700 (PDT) In-Reply-To: <4AC8F8BC.2050905@gmail.com> References: <444951.51198.qm@web33806.mail.mud.yahoo.com> <690707f60910041137l340d2873le86d8f3458188471@mail.gmail.com> <4AC8F8BC.2050905@gmail.com> Date: Mon, 5 Oct 2009 16:23:28 -0600 Message-ID: Subject: Re: reading last inserted record withoud any autoincrement field From: Scott Marlowe To: Rob Sargent Cc: Osvaldo Kussama , m_qoreishy@yahoo.com, pgsql-sql@postgresql.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.465 tagged_above=-10 required=5 tests=AWL=0.134, BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 200910/23 X-Sequence-Number: 33222 On Sun, Oct 4, 2009 at 1:34 PM, Rob Sargent wrote: > Osvaldo Kussama wrote: >> >> 2009/10/4 mohammad qoreishy >> >>> >>> How can get last inserted record in a table without any autoincrement >>> filed? >>> I need to =A0frequently 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 par= t > of current transaction. =A0My fear is OP's schema has no way of identifyi= ng > 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.