Search code examples
postgresqldatetimeunix-timestamp

No value is added into the column


I am trying to find the difference between the Unix seconds and adding into the existing null column but the results are not added into the column. As I am new I can't figure it out.

INSERT INTO "Operation"(minutes)
select (departure_unix_seconds - arrival_unix_seconds)/60  As Difference 
from public."Operation";

Solution

  • assuming you have a column in your table called "minutes" , and you want to update that column , here is the syntax:

    update public."Operation"
    set minutes = (departure_unix_seconds - arrival_unix_seconds)/60 
    

    however usually when a column value depends on other column(s) ,It's better to be implemented as "generated column":

    alter table Operation
    add column minutes generated always as (departure_unix_seconds - arrival_unix_seconds)/60 stored;