A
A
Alistair O2017-07-04 13:54:02
PostgreSQL
Alistair O, 2017-07-04 13:54:02

Need to change the time format in the request, how?

Good afternoon, please help me change the time format from mysql to postgresql

select h.name AS host_name, i.name AS item_name, i.key_ as item_key, FROM_UNIXTIME(hs.clock) AS last_time, hs.value, hs.logeventid
from 
  hosts h 
  join items i on h.hostid = i.hostid
  join history_log hs on i.itemid = hs.itemid
where hs.clock > UNIX_TIMESTAMP() - 86400 and i.hostid = '10458' and hs.logeventid = '4625'
order by last_time, item_name

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Melkij, 2017-07-07
@box4

time format from mysql to postgresql

done by sql design.
Date, time, datetime formats are equivalent. And, emnip, are completely standard for SQL in general.
If you shove data into the wrong data type instead of the regular one for both timestamp subds, then you will be in for surprises sooner or later. This seems to go without saying.
If your clock, as evident from a comment in another answer, is int4 seconds since this epoch, then you can cast unixtime to number-number-of-seconds-of-this-epoch with extract:
You can bring the number of seconds in this epoch to a timestamp using the to_timestamp function.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question