Re: problem with update from subselect

Поиск
Список
Период
Сортировка
От Joe Conway
Тема Re: problem with update from subselect
Дата
Msg-id 3CD02137.2080708@joeconway.com
обсуждение исходный текст
Ответ на problem with update from subselect  (Gary Stainburn <gary.stainburn@ringways.co.uk>)
Список 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-0111: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



В списке pgsql-sql по дате отправления:

Предыдущее
От: Stephan Szabo
Дата:
Сообщение: Re: problem with update from subselect
Следующее
От: j.konzack@arcor.de
Дата:
Сообщение: CREATE VIEW question...