pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
age() vs. timestamp substraction
5+ messages / 4 participants
[nested] [flat]

* age() vs. timestamp substraction
@ 2006-10-05 18:27 Martin Marques <martin@bugs.unl.edu.ar>
  2006-10-05 18:37 ` Re: age() vs. timestamp substraction Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 5+ messages in thread

From: Martin Marques @ 2006-10-05 18:27 UTC (permalink / raw)
  To: pgsql-sql


I just found this problem with the age() function, which AFAIK should give the same resulte as a subtraction of the argument from now(), but it doesn't.


prueba=> SELECT (now() - tc.last_cron),age(tc.last_cron),tc.intervalo FROM tareas_cron tc ;
              ?column?               |              age              | intervalo
-------------------------------------+-------------------------------+-----------
 @ 1 day 15 hours 13 mins 12.06 secs | @ 23 hours 59 mins 58.47 secs | @ 1 day
 @ 15 hours 13 mins 12.06 secs       | @ 1.52 secs ago               | @ 30 mins
 @ 15 hours 13 mins 12.08 secs       | @ 1.50 secs ago               | @ 10 mins

prueba=> SELECT version();
                                        version
----------------------------------------------------------------------------------------
 PostgreSQL 8.1.3 on i486-pc-linux-gnu, compiled by GCC cc (GCC) 4.0.3 (Debian 4.0.3-1)

Any ideas on why?

I starting to change my queries so they don't have the age() function anymore.

--
---------------------------------------------------------
Lic. Martín Marqués         |   SELECT 'mmarques' || 
Centro de Telemática        |       '@' || 'unl.edu.ar';
Universidad Nacional        |   DBA, Programador, 
    del Litoral             |   Administrador
---------------------------------------------------------





^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: age() vs. timestamp substraction
  2006-10-05 18:27 age() vs. timestamp substraction Martin Marques <martin@bugs.unl.edu.ar>
@ 2006-10-05 18:37 ` Tom Lane <tgl@sss.pgh.pa.us>
  2006-10-05 18:43   ` Re: age() vs. timestamp substraction Martin Marques <martin@bugs.unl.edu.ar>
  2006-10-06 09:35   ` Re: age() vs. timestamp substraction Jean-Paul Argudo <jean-paul@argudo.org>
  0 siblings, 2 replies; 5+ messages in thread

From: Tom Lane @ 2006-10-05 18:37 UTC (permalink / raw)
  To: Martin Marques <martin@bugs.unl.edu.ar>; +Cc: pgsql-sql

Martin Marques <martin@bugs.unl.edu.ar> writes:
> I just found this problem with the age() function, which AFAIK should
> give the same resulte as a subtraction of the argument from now(),

Where did you get that idea?  age's reference point is current_date (ie,
midnight) not now().  There are also some differences in the calculation
compared to a plain timestamp subtraction.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: age() vs. timestamp substraction
  2006-10-05 18:27 age() vs. timestamp substraction Martin Marques <martin@bugs.unl.edu.ar>
  2006-10-05 18:37 ` Re: age() vs. timestamp substraction Tom Lane <tgl@sss.pgh.pa.us>
@ 2006-10-05 18:43   ` Martin Marques <martin@bugs.unl.edu.ar>
  1 sibling, 0 replies; 5+ messages in thread

From: Martin Marques @ 2006-10-05 18:43 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-sql


On Thu, 05 Oct 2006 14:37:24 -0400, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Martin Marques <martin@bugs.unl.edu.ar> writes:
>> I just found this problem with the age() function, which AFAIK should
>> give the same resulte as a subtraction of the argument from now(),
> 
> Where did you get that idea?  age's reference point is current_date (ie,
> midnight) not now().  There are also some differences in the calculation
> compared to a plain timestamp subtraction.

Ignore anything I said. Just realized it said current_date. :-(

Sorry.

--
---------------------------------------------------------
Lic. Martín Marqués         |   SELECT 'mmarques' || 
Centro de Telemática        |       '@' || 'unl.edu.ar';
Universidad Nacional        |   DBA, Programador, 
    del Litoral             |   Administrador
---------------------------------------------------------





^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: age() vs. timestamp substraction
  2006-10-05 18:27 age() vs. timestamp substraction Martin Marques <martin@bugs.unl.edu.ar>
  2006-10-05 18:37 ` Re: age() vs. timestamp substraction Tom Lane <tgl@sss.pgh.pa.us>
@ 2006-10-06 09:35   ` Jean-Paul Argudo <jean-paul@argudo.org>
  2006-10-06 13:56     ` Re: age() vs. timestamp substraction Stephan Szabo <sszabo@megazone.bigpanda.com>
  1 sibling, 1 reply; 5+ messages in thread

From: Jean-Paul Argudo @ 2006-10-06 09:35 UTC (permalink / raw)
  To: pgsql-sql; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; Martin Marques <martin@bugs.unl.edu.ar>

Hi all,

> Where did you get that idea?  age's reference point is current_date (ie,
> midnight) not now().  There are also some differences in the calculation
> compared to a plain timestamp subtraction.

I'm jumping on this thread to point out a little strange thing to me.
CURRENT_DATE, converted (stupidly) as a string *with* hour is "current
date at mid-day":


test=# select to_char(current_date,'YYYY-MM-DD HH:MI:SS');
       to_char
---------------------
 2006-10-06 12:00:00
(1 ligne)

It was a day when I had to debug a strange behaviour in a customer's
(bad) code :-)

Cheers,

-- 
Jean-Paul Argudo
www.PostgreSQLFr.org
www.dalibo.com



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: age() vs. timestamp substraction
  2006-10-05 18:27 age() vs. timestamp substraction Martin Marques <martin@bugs.unl.edu.ar>
  2006-10-05 18:37 ` Re: age() vs. timestamp substraction Tom Lane <tgl@sss.pgh.pa.us>
  2006-10-06 09:35   ` Re: age() vs. timestamp substraction Jean-Paul Argudo <jean-paul@argudo.org>
@ 2006-10-06 13:56     ` Stephan Szabo <sszabo@megazone.bigpanda.com>
  0 siblings, 0 replies; 5+ messages in thread

From: Stephan Szabo @ 2006-10-06 13:56 UTC (permalink / raw)
  To: Jean-Paul Argudo <jean-paul@argudo.org>; +Cc: pgsql-sql@postgresql.org, Tom Lane <tgl@sss.pgh.pa.us>; Martin Marques <martin@bugs.unl.edu.ar>

On Fri, 6 Oct 2006, Jean-Paul Argudo wrote:

> Hi all,
>
> > Where did you get that idea?  age's reference point is current_date (ie,
> > midnight) not now().  There are also some differences in the calculation
> > compared to a plain timestamp subtraction.
>
> I'm jumping on this thread to point out a little strange thing to me.
> CURRENT_DATE, converted (stupidly) as a string *with* hour is "current
> date at mid-day":
>
>
> test=# select to_char(current_date,'YYYY-MM-DD HH:MI:SS');
>        to_char
> ---------------------
>  2006-10-06 12:00:00
> (1 ligne)
>
> It was a day when I had to debug a strange behaviour in a customer's
> (bad) code :-)

That's both midnight and mid-day. It's asking for 12 hour time and no
AM/PM marker.



^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2006-10-06 13:56 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-10-05 18:27 age() vs. timestamp substraction Martin Marques <martin@bugs.unl.edu.ar>
2006-10-05 18:37 ` Tom Lane <tgl@sss.pgh.pa.us>
2006-10-05 18:43   ` Martin Marques <martin@bugs.unl.edu.ar>
2006-10-06 09:35   ` Jean-Paul Argudo <jean-paul@argudo.org>
2006-10-06 13:56     ` Stephan Szabo <sszabo@megazone.bigpanda.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox