From: | Medi Montaseri <medi(dot)montaseri(at)intransa(dot)com> |
---|---|
To: | Joe Conway <mail(at)joeconway(dot)com> |
Cc: | pgsql-general <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Arrays ... need clarification.... |
Date: | 2003-04-08 02:15:09 |
Message-ID: | 3E9230AD.3070508@intransa.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Yes....your proposed method is indeed the traditional approach....but
since PG provides
Arrays, I figured "How Nice"....
Thank anyways though...
And the link does not provide much, I stopped by there first, before
asking....
All the examples on the link are using
insert into table values ( x, x, x , ...)
instead of
insert into table (col, col, ...) values ( val, val, ...)
Joe Conway wrote:
> 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
>
From | Date | Subject | |
---|---|---|---|
Next Message | mallah | 2003-04-08 02:36:38 | Re: Age function |
Previous Message | Stephan Szabo | 2003-04-08 02:13:24 | Re: Backpatch FK changes to 7.3 and 7.2? |