From: | Csaba Nagy <nagy(at)ecircle-ag(dot)com> |
---|---|
To: | Sven Van Acker <Sven(dot)Van(dot)Acker(at)vub(dot)ac(dot)be> |
Cc: | Postgres general mailing list <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: viewing the original (chrnological) order of entered |
Date: | 2003-06-10 10:06:49 |
Message-ID: | 1055239610.922.19.camel@coppola.ecircle.de |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
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
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?
>
>
>
From | Date | Subject | |
---|---|---|---|
Next Message | Andrew Gould | 2003-06-10 11:10:12 | Re: Pg_dumpall |
Previous Message | Mattias Kregert | 2003-06-10 10:06:41 | Re: viewing the original (chrnological) order of entered records |