Re: accessing table in LIFO order

From: "Scott Marlowe" <scott(dot)marlowe(at)gmail(dot)com>
To: collins(dot)ethans+psql(at)gmail(dot)com
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: accessing table in LIFO order
Date: 2008-06-07 17:57:13
Message-ID: dcc563d10806071057s5186c9e3g7f19bfa08e57c483@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, Jun 6, 2008 at 3:46 PM, Ethan Collins
<collins(dot)ethans+psql(at)gmail(dot)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.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Charles F. Munat 2008-06-07 18:04:23 Re: PL/pgSQL graph enumeration function hangs
Previous Message Alvaro Herrera 2008-06-07 16:38:42 Re: array column and b-tree index allowing only 8191 bytes