Calculated update

Started by Bret Sternabout 14 years ago4 messagesgeneral
Jump to latest
#1Bret Stern
bret_stern@machinemanagement.com

trying to update a varchar numeric string column
by converting it to int, adding a numeric value and insert it back
as a varchar

Having trouble with cast

#2Rob Sargent
robjsargent@gmail.com
In reply to: Bret Stern (#1)
Re: Calculated update

On 03/12/2012 06:28 PM, Bret Stern wrote:

trying to update a varchar numeric string column
by converting it to int, adding a numeric value and insert it back
as a varchar

Having trouble with cast

Possibly having trouble with two casts: one from string to int, one
from int to string? You sql would help.

#3Bosco Rama
postgres@boscorama.com
In reply to: Bret Stern (#1)
Re: Calculated update

Bret Stern wrote:

trying to update a varchar numeric string column
by converting it to int, adding a numeric value and insert it back
as a varchar

Having trouble with cast

I assume you are doing an update as opposed to an insert. You use
both above (and both numeric and int as well). Anyway, try:

update tbl set col = (col::int + 1);

or some variation thereof. That should do the trick.

Bosco.

#4Bret Stern
bret_stern@machinemanagement.com
In reply to: Bosco Rama (#3)
Re: Calculated update

On Mon, 2012-03-12 at 17:39 -0700, Bosco Rama wrote:

Bret Stern wrote:

trying to update a varchar numeric string column
by converting it to int, adding a numeric value and insert it back
as a varchar

Having trouble with cast

I assume you are doing an update as opposed to an insert. You use
both above (and both numeric and int as well). Anyway, try:

update tbl set col = (col::int + 1);

or some variation thereof. That should do the trick.

Bosco.

update open_orderheader
set order_id = (order_id::int + 3000)
where module_id='aggregate'

worked as advertised.
thanks for the help guys.