Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using function least and greatest on timestamp in PostgreSQL [closed]

How can I use function least/greatest in PostgreSQL on timestamp column?
I have a column - plc_time (timestamp without time zone) and I need to select rows where the plc_time is greatest from two values (the value is timestamp without time zone).
Should I use the conversion? How can I do it?

like image 384
bemol Avatar asked Jul 15 '13 12:07

bemol


People also ask

How do I compare two timestamps in PostgreSQL?

To calculate the difference between the timestamps in PostgreSQL, simply subtract the start timestamp from the end timestamp. Here, it would be arrival - departure . The difference will be of the type interval , which means you'll see it in days, hours, minutes, and seconds.

Should I use timestamp with or without timezone?

Don't use timestamp (without time zone) to store UTC times Storing UTC values in a timestamp without time zone column is, unfortunately, a practice commonly inherited from other databases that lack usable timezone support. Use timestamp with time zone instead.

How do I find the timestamp in PostgreSQL?

The PostgreSQL function LOCALTIMESTAMP returns the current date and time (of the machine running that instance of PostgreSQL) as a timestamp value. It uses the 'YYYY-MM-DD hh:mm:ss. nnnnnnn' format, where: YYYY is a 4-digit year.

What is a PostgreSQL function that returns the current time?

The PostgreSQL CURRENT_TIME function returns the current time and the currentthe time zone.


1 Answers

select *
from some_table
where plc_time = greatest(timestamp '2013-07-15 14:55:00', timestamp '2013-03-01 17:43:00');
like image 88
a_horse_with_no_name Avatar answered Sep 29 '22 14:09

a_horse_with_no_name