K
K
ksvdon2015-09-16 11:20:27
linux
ksvdon, 2015-09-16 11:20:27

How to do time recalculation in MySQL and PostgreSQL?

I had such a script for sqlite:

Date=`/usr/bin/sqlite3 /var/somedb/some.db "select datetime('now')"`
Date_db_dump=`/usr/bin/sqlite3 /var/somedb/some.db "select datetime(ts, 'unixepoch') from some_table order by ts DESC limit 1"`
Date_dif=`/usr/bin/sqlite3 /var/somedb/some.db "SELECT strftime('%s','$Date') - strftime('%s','$Date_db_dump') "`
`/usr/bin/sqlite3 /var/somedb/some.db "update some_table set ts = ts + $Date_dif"`

I can't immediately find something similar for MySQL commands. And I generally know postgre for a couple of days and it will be even worse there. If anyone in the know - tell me pzhlst. how to do.
I’ll describe what I actually need to do just in case if it’s not clear from the script:
Date is the current time
Date_db_dump is the time of the last entry from the table in which I want to recalculate the time (for all table entries, i.e. for the entire 'ts' column)
Date_dif is the time difference between Date and Date_db_dump (in unixtime format)
this line:
`/usr/bin/sqlite3 /var/somedb/some.db "update some_table set ts = ts + $Date_dif"`

changed the value of each row of the ts column. As a result, we receive data with a timestamp such as if we had just received it.
This is necessary for testing, so that when we make a request in the client program, the old (pre-filled) data is displayed as if it were fresh.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Ruslan Fedoseev, 2015-09-16
@martin74ua

update some_table set ts=now()
exactly what you wanted ;)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question