Re: viewing the original (chrnological) order of entered

From: Ron Johnson <ron(dot)l(dot)johnson(at)cox(dot)net>
To: Postgres general mailing list <pgsql-general(at)postgresql(dot)org>
Subject: Re: viewing the original (chrnological) order of entered
Date: 2003-06-10 19:29:18
Message-ID: 1055273358.9312.21.camel@haggis
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(dot)l(dot)johnson(at)cox(dot)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) |
+-----------------------------------------------------------+

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2003-06-10 19:31:19 Re: [GENERAL] Weird postmaster crashes
Previous Message Tom Lane 2003-06-10 19:24:18 Re: age(datfrozenxid)