Run time difference - Postgresql

Asked

Viewed 37 times

1

I need help, I’m a beginner.

I want to catch the difference between minutes and seconds between two columns on the same table, tried the cases below but unsuccessfully. I’m trying to make a SELECT inside the Grafana, extracting directly from a Postgresql base.

SELECT
   justify_hours(column_A,column_B)
FROM table
SELECT
   EXTRACT(DAYS FROM (coluna_A-coluna_B)) as dias,
   EXTRACT(HOURS FROM (coluna_A-coluna_B)) as horas
FROM tabela
SELECT column_A, AGE(column_A,column_B) FROM table WHERE AGE(column_A,column_B) >='1 min'

1 answer

1

Use the Function DATE_PART, to pick up the part of the date you want (days, hours, etc) and the Function AGE which returns the interval between dates.

Taking your example:

SELECT
   EXTRACT(DAYS FROM (coluna_A-coluna_B)) as dias,
   EXTRACT(HOURS FROM (coluna_A-coluna_B)) as horas
FROM tabela

Would look like this:

SELECT
   DATE_PART('day', AGE(coluna_A, coluna_B)) AS dias,
   DATE_PART('hour', AGE(coluna_A, coluna_B)) AS horas,
FROM tabela

You can see it working here: http://sqlfiddle.com/#! 15/7988d/1

Documentation of the date functions of the PostgreSQL: https://www.postgresql.org/docs/8.4/functions-datetime.html

Browser other questions tagged

You are not signed in. Login or sign up in order to post.