Olivia Lundy
Olivia Lundy

Reputation: 127

How to replace integer?

I have a (Postgres) table with a integer column filled epoch (time) value. Yesterday, i made a mistake to fill em up with wrong epoch value. Now i need to change all the time column values 1609804800 to 1609718400 The following:

time
1609804800
1609804800
1609804800
..goes on..

My expect result:

time
1609718400
1609718400
1609718400
..goes on..

My Last query is like:

UPDATE 
   history
SET 
   time = REPLACE(time,1609804800,1609718400)
WHERE 
   condition

I found some useful things at psql reference page about regexp_replace but got:

ERROR: function regexp_replace(integer, unknown, unknown) does not exist LINE 1: select distinct regexp_replace(time, '1609804800', '16097184...

I would like to replace these integer values with new value. I don't know if this is possible but this will speed up things because I have a total of hundreds of rows. I've tried searching Google and StackOverflow, but I cannot see to come up what it is referring to. Can someone explain how and what it is used for? Thank you.

Upvotes: 0

Views: 1924

Answers (2)

Emon46
Emon46

Reputation: 1626

you need to put your condition in where. and the condition will be WHERE time = 1609804800.

here template is like SET Colum_name = value(with which you want to update) WHERE (put your conditions here ) and in your case it is WHERE time = 1609804800

UPDATE history
   SET time = 1609718400
WHERE 
   time  = 1609804800

ref

Upvotes: 1

Popeye
Popeye

Reputation: 35910

You can use one more WHERE condition as follows:

UPDATE history
   SET time = 1609718400
 WHERE time  = 1609804800
   and ...condition...

Upvotes: 1

Related Questions