Skip site navigation (1) Skip section navigation (2)

Re: Calculation in update query

From: Oliver Fromme <olli(at)lurza(dot)secnetix(dot)de>
To: cgoodfellow(at)tealuxe(dot)com
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Calculation in update query
Date: 2004-09-30 16:58:16
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-novice
Christopher A. Goodfellow wrote:
 > So I do need to read (select) the value first, perform the calculation, and
 > then update the value?  I just wanted to be able to set the value based on
 > the current value in one step.  There are 10's of thousands of calculations
 > that will be performed in this loop.  Three steps (Select, Calculate,
 > Update) are just longer than one.  Thanks.

Ah, sorry, I misunderstood you.  I thought you were
concerned about the possibility of concurrent updates,
i.e. the necessity of locking.  That's why my brain
immediately went into the SELECT FOR UPDATE direction.

Well, yes, of course you can update a column based on
the old value of that column.  The UPDATE command
accepts arbitrary expressions for the new value which
may reference the old one.  There's even an example
which does exactly that (on the PostgreSQL's doc page
on the UPDATE command):

Best regards

Oliver Fromme, secnetix GmbH & Co KG, Oettingenstr. 2, 80538 M√ľnchen
Any opinions expressed in this message may be personal to the author
and may not necessarily reflect the opinions of secnetix in any way.

"The ITU has offered the IETF formal alignment with its
corresponding technology, Penguins, but that won't fly."
        -- RFC 2549

pgsql-novice by date

Next:From: brewDate: 2004-10-01 17:20:01
Subject: Re: Brand New User (I hope)
Previous:From: Oliver FrommeDate: 2004-09-30 16:03:06
Subject: Re: Calculation in update query

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group