Skip site navigation (1) Skip section navigation (2)

Re: Getting The Last Entry

From: Thom Brown <thom(at)linux(dot)com>
To: Rodrigo Quezada <rotarantino(at)gmail(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Getting The Last Entry
Date: 2010-09-09 22:21:36
Message-ID: AANLkTi=zGngzXJGPg0k-nycPsULF_rvLLg2EN12=-xpw@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-novice
On 9 September 2010 23:13, Rodrigo Quezada <rotarantino(at)gmail(dot)com> wrote:
> Hello,
> I need to get de last entry from a table. I try using:
> DECLARE variable CURSOR FOR SELECT id FROM table;
> FETCH LAST FROM variable;
> And works fine, but when i try to use this code in a procedure, appears the
> following message:
> ERROR:  syntax error at or near "FETCH"
> LINE XX:  FETCH LAST FROM raton;
>           ^
> ********** Error **********
> Is there another way to get that last ID?

Try:

SELECT id FROM table ORDER BY id DESC LIMIT 1;

-- 
Thom Brown
Twitter: @darkixion
IRC (freenode): dark_ixion
Registered Linux user: #516935

In response to

Responses

pgsql-novice by date

Next:From: Machiel RichardsDate: 2010-09-10 07:03:52
Subject: Postgresql & Deadlocks
Previous:From: Bastiaan OlijDate: 2010-09-09 22:15:24
Subject: Any known problems installing PG 8.4.4 on Win 2008 R2?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group