From: | Jeff Butera <jbutera(at)linus(dot)highpoint(dot)edu> |
---|---|
To: | pgsql-general(at)postgreSQL(dot)org |
Subject: | PG UPDATE question |
Date: | 2001-03-21 06:22:07 |
Message-ID: | Pine.LNX.4.21.0103210121060.21956-100000@linus.highpoint.edu |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
I'm new to postgres and am having an UPDATE problem when
using a join. I've got two tables like so:
CREATE TABLE QUESTION_ANSWERS (
QUESTIONS_ID int4 NOT NULL, -- question ID
ANSWERS_ID int4 NOT NULL, -- answer ID
CORRECT boolean
);
CREATE TABLE STUDENT_ANSWERS (
STUDENTS_ID int4 NOT NULL, -- student ID
QUESTIONS_ID int4 NOT NULL, -- question ID
ANSWERS_ID int4 NOT NULL, -- answer ID
CORRECT boolean
);
The table QUESTION_ANSWERS is completely populated. The table
STUDENT_ANSWERS has all fields except CORRECT populated. I want to
write an update that'll copy CORRECT from QUESTION_ANSWERS into
STUDENT_ANSWERS when the IDs match. Here's what I wrote:
UPDATE STUDENT_ANSWERS SET CORRECT=QA.CORRECT
FROM QUESTION_ANSWERS QA,STUDENT_ANSWERS SA
WHERE SA.CORRECT=null
AND SA.QUESTIONS_ID=QA.QUESTIONS_ID
AND SA.ANSWERS_ID=QA.ANSWERS_ID;
It executes without an error and correctly returns the count of the
records in the join, but the CORRECT field in STUDENT_ANSWERS is
populated entirely with false regardless of what CORRECT is
QUESTION_ANSWERS.
Can anyone shed light on what I'm missing?
--
Jeff Butera, Ph.D. Junk e-mail is like
Department of Mathematics & Computer Science plastic grocery bags:
High Point University they just seem to
jbutera(at)linus(dot)highpoint(dot)edu multiply at will...
http://linus.highpoint.edu/~jbutera Anonymous
From | Date | Subject | |
---|---|---|---|
Next Message | Tatsuo Ishii | 2001-03-21 06:36:07 | Re: Call for platforms |
Previous Message | Tom Lane | 2001-03-21 05:24:29 | Re: Upgrade 6.5 to 7.0.3 or 7.1 beta? |