dbTalk Databases Forums  

[BUGS] Inconsistent behavior with AGE()

mailing.database.pgsql-bugs mailing.database.pgsql-bugs


Discuss [BUGS] Inconsistent behavior with AGE() in the mailing.database.pgsql-bugs forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Josh Berkus
 
Posts: n/a

Default [BUGS] Inconsistent behavior with AGE() - 10-28-2004 , 03:57 PM






Folks,

Pardon me if this is redundant, but again the pgsql-bugs archives are not
working.

Summary: Various versions of AGE() give inconsistent results
Versions Tested: 7.4.2, 7.4.3, 8.0b4
Severity: Annoyance
Description: The age() built-in function sometimes truncates hours, minutes
and seconds, and sometimes it doesn't, depending on the parameters. This
seems inconsistent and confusing.

gforge=> select age('2004-01-01'::TIMESTAMP);
age
----------------
9 mons 27 days
(1 row)

gforge=> select age(now(),'2004-01-01'::TIMESTAMP);
age
------------------------------------
9 mons 27 days 11:17:19.8895479999
(1 row)

--
--Josh

Josh Berkus
Aglio Database Solutions
San Francisco

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Reply With Quote
  #2  
Old   
Tom Lane
 
Posts: n/a

Default Re: [BUGS] Inconsistent behavior with AGE() - 10-28-2004 , 05:33 PM






Josh Berkus <josh (AT) agliodbs (DOT) com> writes:
Quote:
Description: The age() built-in function sometimes truncates hours, minutes
and seconds, and sometimes it doesn't, depending on the parameters. This
seems inconsistent and confusing.

gforge=> select age('2004-01-01'::TIMESTAMP);
age
----------------
9 mons 27 days
(1 row)

gforge=> select age(now(),'2004-01-01'::TIMESTAMP);
age
------------------------------------
9 mons 27 days 11:17:19.8895479999
(1 row)
Actually, the definition of the single-parameter variants of age() is
age(current_date, $1)
not
age(now(), $1)

I'm not sure this is wrong, but perhaps it should be better documented.

Another point is that when you use now() (which returns timestamptz),
I believe you will get the timestamp promoted to timestamptz (which
introduces your timezone setting into the equation!) and then
the timestamptz variant of age() will be invoked. But age(TIMESTAMP)
is going to select the plain-timestamp variant, which will do a
non-DST-aware subtraction.

Thus for example:

regression=# select age(current_timestamp,'2004-01-01'::TIMESTAMP);
age
------------------------------------
9 mons 27 days 17:19:08.1852230001
(1 row)

regression=# select age(localtimestamp,'2004-01-01'::TIMESTAMP);
age
--------------------------------
9 mons 27 days 18:19:16.610111
(1 row)

regression=# select age(current_date,'2004-01-01'::TIMESTAMP);
age
----------------
9 mons 27 days
(1 row)

The first two answers differ by the amount of the (single) DST
transition that has occurred since 1/1. In another few days
they'd not differ anymore.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html


Reply With Quote
  #3  
Old   
Josh Berkus
 
Posts: n/a

Default Re: [BUGS] Inconsistent behavior with AGE() - 10-28-2004 , 05:47 PM



Tom,

Quote:
Actually, the definition of the single-parameter variants of age() is
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0ag e(current_date, $1)
not
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0ag e(now(), $1)

I'm not sure this is wrong, but perhaps it should be better documented.
Hmmm ... well, if that's the definition, then we probably don't need to cha=
nge=20
it.=20=20

--Josh

--=20
--Josh

Josh Berkus
Aglio Database Solutions
San Francisco

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.