Re: Update question - Mailing list pgsql-sql

From Gábriel Ákos
Subject Re: Update question
Date
Msg-id 4429739F.6020205@i-logic.hu
Whole thread Raw
In response to Re: Update question  (Markus Schaber <schabi@logix-tt.com>)
Responses Re: Update question
List pgsql-sql
Markus Schaber wrote:
> 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
> 

This is ok, but this is redundant, i guess. you should put edge_id and
cost into another table and use join to retrieve cost for each id.
put a key on edge_id, most likely a primary (unique) key.


-- 
Üdvözlettel,
Gábriel Ákos
-=E-Mail :akos.gabriel@i-logic.hu|Web:  http://www.i-logic.hu=-
-=Tel/fax:+3612367353            |Mobil:+36209278894            =-



pgsql-sql by date:

Previous
From: Markus Schaber
Date:
Subject: Re: Update question
Next
From: "Fay Du"
Date:
Subject: Re: Update question