pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Stephan Szabo <sszabo@megazone23.bigpanda.com>
To: Gary Stainburn <gary.stainburn@ringways.co.uk>
Cc: pgsql-sql@postgresql.org
Subject: Re: problem with update from subselect
Date: Wed, 1 May 2002 09:55:47 -0700 (PDT)
Message-ID: <20020501095436.Q24344-100000@megazone23.bigpanda.com> (raw)
In-Reply-To: <E172wxt-0007vR-00@stan.ringways.co.uk>


On Wed, 1 May 2002, 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);

Do you really want to join with another "trip" in the subselect?

I think you probably want something like:
update trip set trip_arrive = (select trip.trip_depart + r.route_time
 from route r where r.routeid=trip.trip_route);




view thread (3+ messages)  latest in thread

Message-ID: <20020501095436.Q24344-100000@megazone23.bigpanda.com>
Permalink:  ../20020501095436.Q24344-100000@megazone23.bigpanda.com/
Also on:    postgresql.org/message-id/20020501095436.Q24344-100000@megazone23.bigpanda.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: sszabo@megazone23.bigpanda.com, gary.stainburn@ringways.co.uk
  Subject: Re: problem with update from subselect
  In-Reply-To: <20020501095436.Q24344-100000@megazone23.bigpanda.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox