Re: Arrays ... need clarification....

From: Joe Conway <mail(at)joeconway(dot)com>
To: Medi Montaseri <medi(dot)montaseri(at)intransa(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Arrays ... need clarification....
Date: 2003-04-08 01:29:33
Message-ID: 3E9225FD.1050705@joeconway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Medi Montaseri wrote:
> I can use some clarification on Array usage....
>
> Given the following definition....
>
> create table test ( name varchar(20) , grades integer[]);
>
> How do I insert a new record, I see multiple ways of doing it but if one
> does
> not do this right, then updates will fail....

I think this is probably a misuse of arrays. You might better model this
as something like:

create table student (
student_id serial primary key,
name text
);
create table test (
test_id serial primary key,
date_taken timestamp,
description text
);
create table grade (
grade_id serial primary key,
test_id int references test,
student_id int references student,
test_grade int
);

Now you can do something like:
select s.name, avg(g.test_grade), stddev(g.test_grade) as average from
student s, test t, grade g where s.student_id = g.student_id and
g.test_id = t.test_id and t.date_taken between '01-01-2003' and
'03-31-2003' group by s.name;

But in any case, see:
http://www.postgresql.org/docs/view.php?version=7.3&idoc=1&file=arrays.html
for more information on use of arrays.

Joe

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tatsuo Ishii 2003-04-08 01:37:50 Re: Backpatch FK changes to 7.3 and 7.2?
Previous Message Christopher Kings-Lynne 2003-04-08 01:24:37 Re: Backpatch FK changes to 7.3 and 7.2?