1 May 2002 19:29
problem with update from subselect
Gary Stainburn <gary.stainburn <at> ringways.co.uk>
2002-05-01 17:29:34 GMT
2002-05-01 17:29:34 GMT
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);
Database definition:
drop table route;
drop table trip;
drop sequence route_id_seq;
drop sequence trip_id_seq;
create sequence "route_id_seq" start 1 increment 1;
create sequence "trip_id_seq" start 1 increment 1;
create table route (
routeid int4 unique default nextval('route_id_seq'::text) not null,
route_depart character (4), -- std ICAO code e.g. EGNM
route_dest character (4), -- ditto
route_time interval,
primary key (routeid)
);
create table trip (
tripid int4 unique default nextval('trip_id_seq'::text) not null,
trip_route int4 references route(routeid),
trip_depart timestamp, -- departure time
(Continue reading)
RSS Feed