From: | Joe Conway <mail(at)joeconway(dot)com> |
---|---|
To: | Gary Stainburn <gary(dot)stainburn(at)ringways(dot)co(dot)uk> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: problem with update from subselect |
Date: | 2002-05-01 17:09:11 |
Message-ID: | 3CD02137.2080708@joeconway.com |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Gary Stainburn wrote:
> Hi all, using the schema described below, I want to be able to update each
> arrival time from departure times and trip lengths.
>
> However the update fails because the subselect returns all three answers.
>
> How would I correct the update to make it work
>
> update trip set trip_arrive = (select t.trip_depart + r.route_time
> from route r, trip t where r.routeid = t.trip_route);
>
If I understand what you're trying to do correctly, this works:
test=# update trip set trip_arrive = trip_depart + r.route_time from
route r where r.routeid = trip.trip_route; UPDATE 3
test=# select * from trip;
tripid | trip_route | trip_depart | trip_arrive
--------+------------+---------------------+---------------------
1 | 1 | 2002-01-01 10:00:00 | 2002-01-01 11:40:00
2 | 1 | 2002-02-01 11:30:00 | 2002-02-01 13:10:00
3 | 2 | 2002-01-01 11:00:00 | 2002-01-01 11:30:00
(3 rows)
HTH,
Joe
From | Date | Subject | |
---|---|---|---|
Next Message | Gary Stainburn | 2002-05-01 17:29:34 | problem with update from subselect |
Previous Message | Stephan Szabo | 2002-05-01 16:55:47 | Re: problem with update from subselect |