Re: Using UPDATE FROM - Mailing list pgsql-sql

From Tom Lane
Subject Re: Using UPDATE FROM
Date
Msg-id 7574.1094883423@sss.pgh.pa.us
Whole thread Raw
In response to Using UPDATE FROM  (Collin Peters <cpeters@mcrt.ca>)
List pgsql-sql
Collin Peters <cpeters@mcrt.ca> writes:
> Here is the UPDATE statement:

> UPDATE programactivitysets SET repsvalue = reps_actual
> FROM workouts w, workoutactivities wa, workoutactivitysets was, 
> programactivities pa, programactivitysets pas
> WHERE wa.workout_id = w.workout_id
> AND was.workoutactivity_id = wa.workoutactivity_id
> AND pa.programactivity_id = wa.programactivity_id
> AND pas.programactivity_id = pa.programactivity_id
> AND pas.set = was.set
> AND w.workout_id = 6036;

I think you're imagining that "programactivitysets pas" in the FROM
clause is the same as the target table "programactivitysets".  It's
not, at least not in Postgres, though I've heard tell that MS SQL
interprets it that way for some unfathomable reason.

Drop the FROM entry and s/pas/programactivitysets/ in the WHERE
clause, and I think you'll be good to go ...
        regards, tom lane


pgsql-sql by date:

Previous
From: Tom Lane
Date:
Subject: Re: [GENERAL] PL/pgSQL Function Problem
Next
From: Tom Lane
Date:
Subject: Re: CREATE RULE ignored, what did I do wrong