UPDATE from a SELECT on two fields.

From: Roy Souther <roy(at)SiliconTao(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: UPDATE from a SELECT on two fields.
Date: 2005-07-08 23:31:58
Message-ID: 1120865518.16796.9.camel@UtopiaPlanetia
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I have been useing an UPDATE from a SELECT on a single field and it
works great.

Example:
UPDATE reports.mytemptable SET igka =
(SELECT
CASE
WHEN value >= 0 THEN value || ' (G}'
WHEN value < 0 THEN (value * -1) || ' (K)'
END
FROM (
SELECT ((mmpuncorvol - uutuncorvol)::float4 / 1000)::NUMERIC(5,3) AS
value
FROM runs
WHERE status ILIKE '%init%'
AND status ILIKE '%fast%'
AND inactive='f'
AND evaluation = reports.mytemptable.eid ) AS idontcare)

To save some time I would like it to update two fields at the same time
but I cannot wrap my head around how that could be done. Can it not be
done?

I would like to make it do something like this...
Example:
UPDATE reports.mytemptable SET igkrv = mmpuncorvol, igka =
givekeepamount FROM (
SELECT mmpuncorvol,
CASE
WHEN value >= 0 THEN value || ' (G}'
WHEN value < 0 THEN (value * -1) || ' (K)'
END AS givekeepamount
FROM (
SELECT mmpuncorvol, ((mmpuncorvol - uutuncorvol)::float4 /
1000)::NUMERIC(5,3) AS value
FROM runs
WHERE status ILIKE '%init%'
AND status ILIKE '%fast%'
AND inactive='f'
AND evaluation = reports.mytemptable.eid ) AS idontcare) AS
stilldontcare

Any ideas?

Roy Souther
www.SiliconTao.com
Let Open Source help your business move beyond.

For security this message is digitally authenticated by GnuPG.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Geert Jansen 2005-07-09 11:13:13 Transaction isolation levels
Previous Message Michael Fuhr 2005-07-08 22:53:56 Re: Postgresql 7.4.8 inconsistent index usage