Re: viewing the original (chrnological) order of entered - Mailing list pgsql-general

From Ron Johnson
Subject Re: viewing the original (chrnological) order of entered
Date
Msg-id 1055273358.9312.21.camel@haggis
Whole thread Raw
In response to Re: viewing the original (chrnological) order of entered  (Csaba Nagy <nagy@ecircle-ag.com>)
List pgsql-general
On Tue, 2003-06-10 at 05:06, Csaba Nagy wrote:
> No, at least not as you expect it. SQL returns the found records in
> random order except for the explicit "order by" clause. So if you want a

Following up on this: the reason it does not happen is because the
relational algebra that underpins relations DBMSs acts on un-ordered
sets.

This is different from old pseudo-RDBMSs like dBASEIII in which you
had to explicitly access rows by number.

> chronological order, you have to supply some ordering fields to the
> order by clause. This could be achieved easily by normalizing your
> table, i.e. create a table like:
> create table ages (
>     age_id smallint primary key,
>     sort_order smallint,
>     age_name varchar(100)
> );
> insert into ages values (1, 10, 'childhood');
> insert into ages values (2, 20, 'high school');
> insert into ages values (3, 30, 'univesrity');
>
> NOTE: leave gaps in the sort order to accommodate for later insertions.
>
> Then in the original table replace the names with age_id, and use a join
> on the 2 tables, sorting by original_table.person_id, ages.sort_order.
>
> HTH,
> Csaba.
>
>
> On Tue, 2003-06-10 at 11:50, Sven Van Acker wrote:
> > Hi
> >
> >
> >
> > I've the following problem:
> >
> >
> >
> > I have a 2-column table with columns "person_id"(int4) and "phase"(text).
> >
> >
> >
> > When I entered the following records in a chronological fashion: <1, "high
> > school">; <1, "childhood"> and <2, "university">;
> >
> >
> >
> >
> >
> > I requested the following select-statement.
> >
> >
> >
> > SELECT person_id, phase FROM life ORDER BY person_id
> >
> >
> >
> > And found the tuple <1, "childhood"> before the tuple <1, "high school">.
> >
> >
> >
> > I want to view the chronological order of my entries, but ordered by
> > person_id.
> >
> > Is this possible in postgresql?
> >

--
+-----------------------------------------------------------+
| Ron Johnson, Jr.     Home: ron.l.johnson@cox.net          |
| Jefferson, LA  USA   http://members.cox.net/ron.l.johnson |
|                                                           |
| Regarding war zones: "There's nothing sacrosanct about a  |
| hotel with a bunch of journalists in it."                 |
|     Marine Lt. Gen. Bernard E. Trainor (Retired)          |
+-----------------------------------------------------------+


pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: age(datfrozenxid)
Next
From: Tom Lane
Date:
Subject: Re: Weird postmaster crashes