Re: UPDATE table .....

From: Pandurangan R S <pandurangan(dot)r(dot)s(at)gmail(dot)com>
To: Maik Trömel <maik(dot)troemel(at)maitro(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: UPDATE table .....
Date: 2005-12-13 12:33:08
Message-ID: 5e744e3d0512130433y2e2ea8bbid0b94b9701c3bf08@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

UPDATE
geom_summen a
SET
a.var228= a.var228 + (SELECT b.var228 FROM geom_ns_wrf b
WHERE b.gid=a.gid);

Use Coalesce if you want to substitute zero for null, otherwise the
column will be updated to null, if any of the values that was summed
was null.

On 12/13/05, Maik Trömel <maik(dot)troemel(at)maitro(dot)net> wrote:
> /Hi,
>
> I want to update a column (integer). The value that should be set is the
> sum of the column I want to update and an integer column from another
> table with similiar information an the same primary key "gid".
>
> It should work this way:
>
> Table1 + Table2 = Updated Table1
> gid var228// gid var228// gid var228/
> /1 1 1 3 1
> 4
> 2 2 2 2 2
> 4
> 3 1 3 7 3
> 8
>
>
> I tried some insturctions like:
>
> UPDATE
> geom_summen
> SET
> var228=( SELECT
> (geom_summen.var228 + geom_ns_wrf.var228)
> FROM
> geom_summen, geom_ns_wrf
> WHERE
> geom_summen.gid=geom_ns_wrf.gid )
> WHERE
> geom_summen.gid=geom_ns_wrf.gid;
>
> But all of them don't work.
> I know it can't be very difficult. But I can't get the solution.
> Probably someone can help me.
>
> Thank for help!
>
> Maik
> /
>
> ---------------------------(end of broadcast)---------------------------
> TIP 9: In versions below 8.0, the planner will ignore your desire to
> choose an index scan if your joining column's datatypes do not
> match
>

--
Regards
Pandu

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Ezequias Rodrigues da Rocha 2005-12-13 14:28:18 Re: [postgis-users] Re: [Freegis-list] Re: [GENERAL]
Previous Message Maik Trömel 2005-12-13 12:20:45 UPDATE table .....