Forum OpenACS Development: update query problem

Collapse
Posted by yo ha on
Hi,

This problem is is to do with the update query command in postgresql.

What i want to do is to update one table using data from another table.

This is what i want my query to do:

UPDATE ccf_claim_records, acs_objects
SET ccf_claim_records.processed = true
WHERE ccf_claim_records.processed = false
AND ccf_claim_records.supervisor_id = :s_id
AND ccf_claim_records.claim_record_id = acs_objects.object_id
AND acs_objects.creation_user = :id

where s_id and :id are passed in as parameters.

Since postgresql doesnt allow for defining multiple tables in the update command, i have tried to do the query using the WHERE EXISTS clause, however i still cannot manage to get the query out.

Could someone please help me in writing this query.

Thanks for your help,

Yo.

Collapse
2: Re: update query problem (response to 1)
Posted by russ m on
how did you express the query using EXISTS? I'd think this should work -

UPDATE ccf_claim_records
SET ccf_claim_records.processed = true
WHERE ccf_claim_records.processed = false
AND ccf_claim_records.supervisor_id = :s_id
AND EXISTS (
  SELECT 1 from acs_objects
  WHERE acs_objects.object_id = ccf_claim_records.claim_record_id
  AND acs_objects.creation_user = :id
)

which will mark as processed all records for a particular user/supervisor pair...

Collapse
3: Re: update query problem (response to 1)
Posted by yo ha on
Thanks russell, I now have the query going.