Re: accessing table in LIFO order - Mailing list pgsql-general

From Scott Marlowe
Subject Re: accessing table in LIFO order
Date
Msg-id dcc563d10806071057s5186c9e3g7f19bfa08e57c483@mail.gmail.com
Whole thread Raw
In response to accessing table in LIFO order  ("Ethan Collins" <collins.ethans+psql@gmail.com>)
List pgsql-general
On Fri, Jun 6, 2008 at 3:46 PM, Ethan Collins
<collins.ethans+psql@gmail.com> wrote:
> I have got a table that holds 2 columns: date_id and info. date_id is
> bigint, created as, for eg. 17 May 2008, 19:05 hrs => 200805171905. This
> table is populated with {date, info} pair that I receive frequently. AND
> there can be mltiple such entries with a single date_id but varying info,
> for eg. 20 entries with same date_id but different info. I haven't created
> any primary key or index.
> I use query that looks like this:
> SELECT date_id, info FROM netproto_entries ORDER BY date_id DESC
> LIMIT <limit_val>;
> Questions:
> - For higher values of limit_val (say 70/75/..), when I change it, the order
>   in which I get the entries changes. Eg. it shows me one info at the top at
>   one time, and another on the next time with a different value of
> limit_val.
> - My intent is to fetch the entries from the database in LIFO order, most
>   recently entered entry at the top. For the elements with the date_id being
>   the same, they are not in LIFO order. I understand that I can add another
>   incrementing index column and sort the table based on that. But, without
> adding this,
>   does postgresql have any method/configuration to get me output in LIFO
> order ?

How is it to tell which record is which?

>   And are there any better methods available compared to adding another
> index
>   column (as mentioned above) ?

No need for another index.  Just create a serial column and use it to
break the ties.

pgsql-general by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: array column and b-tree index allowing only 8191 bytes
Next
From: "Charles F. Munat"
Date:
Subject: Re: PL/pgSQL graph enumeration function hangs