Re: Getting The Last Entry - Mailing list pgsql-novice

From Thom Brown
Subject Re: Getting The Last Entry
Date
Msg-id AANLkTi=zGngzXJGPg0k-nycPsULF_rvLLg2EN12=-xpw@mail.gmail.com
Whole thread Raw
In response to Getting The Last Entry  (Rodrigo Quezada <rotarantino@gmail.com>)
List pgsql-novice
On 9 September 2010 23:13, Rodrigo Quezada <rotarantino@gmail.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

pgsql-novice by date:

Previous
From: Bastiaan Olij
Date:
Subject: Any known problems installing PG 8.4.4 on Win 2008 R2?
Next
From: Machiel Richards
Date:
Subject: Postgresql & Deadlocks