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
Views: Raw Message | Whole Thread | Download mbox | Resend email
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

Browse pgsql-novice by date

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