0

got stuck on something I assumed would be easy. I am trying to update an EPOCH column from year 2013 to 2015 for some test data.

I tried:

update cache set "Time" = "Time" + 31556926*2  
where date_part('year', to_timestamp("Time")) = '2013';

But that did not only change the year, but also the other values, Month/Day and Time now are all messed up.

What is the correct syntax to get ONLY the year updated in a table please?

Steve
  • 1,028
  • 7
  • 25
  • 42

2 Answers2

0

Here is what worked:

update "diskspacebyfilesys" 
set "Time" = (select extract ('epoch' from (to_timestamp("Time") + interval '1 year'))) 
where date_part('year', to_timestamp("Time")) = '2013';
Steve
  • 1,028
  • 7
  • 25
  • 42
0

Filtering by date_part('year', to_timestamp("Time")) = '2013' works but it is not sargable, and it's not too bad for occasional admin jobs, but for regular updates you might consider the following instead:

update "diskspacebyfilesys" 
  set "Time" = extract ('epoch' from to_timestamp("Time") + interval '1 year') 
where "Time" >= extract('epoch' from '2013-01-01'::date) and
      "Time" < extract('epoch' from '2014-01-01'::date);
Community
  • 1
  • 1
Ezequiel Tolnay
  • 4,302
  • 1
  • 19
  • 28