Re: Update question - Mailing list pgsql-sql

From Markus Schaber
Subject Re: Update question
Date
Msg-id 442969AB.2020604@logix-tt.com
Whole thread Raw
In response to Update question  ("Fay Du" <fay.du@versaterm.com>)
Responses Re: Update question
List pgsql-sql
Hi, Fay,

Fay Du wrote:
> Table cost
> 
> Id  edge_id    cost
> 1       30         101.4
> 2       30          null
> 3       40          500.2
> 4       40           null
> 5        45          300.7
> 6        45           null

> I want to set cost value with same edge_id by same value. The existing
> values are calculated by calling a function (calculate edge length). I
> can calculate the value by same function, but the function was slow. I
> wander if I can use update statement to set the second value with same
> edge_id. Thanks in advance for your help.

It should go like:

UPDATE cost SET edge_id = (SELECT cost FROM cost innr WHERE innr.edge_id
= edge_id AND innr.cost is not null) WHERE cost is null;

HTH,
Marku

-- 
Markus Schaber | Logical Tracking&Tracing International AG
Dipl. Inf.     | Software Development GIS

Fight against software patents in EU! www.ffii.org www.nosoftwarepatents.org


pgsql-sql by date:

Previous
From: "Fay Du"
Date:
Subject: Update question
Next
From: Gábriel Ákos
Date:
Subject: Re: Update question