Lists: | pgsql-hackers |
---|
From: | Christopher Kings-Lynne <chriskl(at)familyhealth(dot)com(dot)au> |
---|---|
To: | PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Oddity with extract microseconds? |
Date: | 2005-12-06 15:39:44 |
Message-ID: | 4395B0C0.1000607@familyhealth.com.au |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
Does anyone else find this odd:
mysql=# select extract(microseconds from timestamp '2005-01-01
00:00:00.123');
date_part
-----------
123000
(1 row)
mysql=# select extract(microseconds from timestamp '2005-01-01
00:00:01.123');
date_part
-----------
1123000
(1 row)
No other extracts include other fields. eg, minutes:
mysql=# select extract(minutes from timestamp '2005-01-01 00:10:00');
date_part
-----------
10
(1 row)
mysql=# select extract(minutes from timestamp '2005-01-01 10:10:00');
date_part
-----------
10
So how come microseconds includes the microseconds from the 'seconds'
field and not just after the '.'? And if it's supposed to include
'seconds', then why doesn't it include minutes, hours, etc.?
Chris
From: | Christopher Kings-Lynne <chriskl(at)familyhealth(dot)com(dot)au> |
---|---|
To: | PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Oddity with extract microseconds? |
Date: | 2005-12-06 15:44:36 |
Message-ID: | 4395B1E4.9070308@familyhealth.com.au |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
OK, AndrewSN just pointed out that it's "documented" to work like that...
...still seems bizarre...
Chris
Christopher Kings-Lynne wrote:
> Does anyone else find this odd:
>
> mysql=# select extract(microseconds from timestamp '2005-01-01
> 00:00:00.123');
> date_part
> -----------
> 123000
> (1 row)
>
> mysql=# select extract(microseconds from timestamp '2005-01-01
> 00:00:01.123');
> date_part
> -----------
> 1123000
> (1 row)
>
> No other extracts include other fields. eg, minutes:
>
> mysql=# select extract(minutes from timestamp '2005-01-01 00:10:00');
> date_part
> -----------
> 10
> (1 row)
>
> mysql=# select extract(minutes from timestamp '2005-01-01 10:10:00');
> date_part
> -----------
> 10
>
> So how come microseconds includes the microseconds from the 'seconds'
> field and not just after the '.'? And if it's supposed to include
> 'seconds', then why doesn't it include minutes, hours, etc.?
>
> Chris
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: don't forget to increase your free space map settings
From: | Alvaro Herrera <alvherre(at)commandprompt(dot)com> |
---|---|
To: | Christopher Kings-Lynne <chriskl(at)familyhealth(dot)com(dot)au> |
Cc: | PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Oddity with extract microseconds? |
Date: | 2005-12-06 16:48:40 |
Message-ID: | 20051206164840.GA9690@surnet.cl |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
Christopher Kings-Lynne wrote:
> OK, AndrewSN just pointed out that it's "documented" to work like that...
>
> ...still seems bizarre...
So it's a "gotcha"!
--
Alvaro Herrera http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support
From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Christopher Kings-Lynne <chriskl(at)familyhealth(dot)com(dot)au> |
Cc: | PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Oddity with extract microseconds? |
Date: | 2005-12-06 17:03:14 |
Message-ID: | 4748.1133888594@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
Christopher Kings-Lynne <chriskl(at)familyhealth(dot)com(dot)au> writes:
> OK, AndrewSN just pointed out that it's "documented" to work like that...
> ...still seems bizarre...
It seems reasonably consistent to me. extract() doesn't consider
seconds and fractional seconds to be distinct fields: it's all one
value. The milliseconds and microseconds options just shift the
decimal place for you.
regards, tom lane
From: | Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | Christopher Kings-Lynne <chriskl(at)familyhealth(dot)com(dot)au>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Oddity with extract microseconds? |
Date: | 2005-12-06 17:09:19 |
Message-ID: | 200512061709.jB6H9JD16121@candle.pha.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
Tom Lane wrote:
> Christopher Kings-Lynne <chriskl(at)familyhealth(dot)com(dot)au> writes:
> > OK, AndrewSN just pointed out that it's "documented" to work like that...
> > ...still seems bizarre...
>
> It seems reasonably consistent to me. extract() doesn't consider
> seconds and fractional seconds to be distinct fields: it's all one
> value. The milliseconds and microseconds options just shift the
> decimal place for you.
I think this illustrates the issue:
test=> SELECT date_part('microseconds', '00:00:01.33'::time);
date_part
-----------
1330000
(1 row)
test=> SELECT date_part('microseconds', '00:03:01.33'::time);
date_part
-----------
1330000
(1 row)
Why aren't 'minutes' considered too? Because they aren't 'seconds'.
Well, seconds aren't microseconds either.
--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073
From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> |
Cc: | Christopher Kings-Lynne <chriskl(at)familyhealth(dot)com(dot)au>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Oddity with extract microseconds? |
Date: | 2005-12-06 17:19:58 |
Message-ID: | 4915.1133889598@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> writes:
> Why aren't 'minutes' considered too? Because they aren't 'seconds'.
> Well, seconds aren't microseconds either.
Yeah, they are: it's just one field. The other way of looking at it
(that everything is seconds) is served by "extract(epoch)".
regards, tom lane
From: | Christopher Kings-Lynne <chriskl(at)familyhealth(dot)com(dot)au> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Oddity with extract microseconds? |
Date: | 2005-12-07 01:43:30 |
Message-ID: | 43963E42.8010408@familyhealth.com.au |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
>>Why aren't 'minutes' considered too? Because they aren't 'seconds'.
>>Well, seconds aren't microseconds either.
>
> Yeah, they are: it's just one field. The other way of looking at it
> (that everything is seconds) is served by "extract(epoch)".
Well, it's different in MySQL unfortunately - what does the standard
say? Out of interest, can someone try this for me in MySQL 5:
SELECT EXTRACT (MICROSECOND FROM '2003-01-02 10:30:00.00123');
SELECT EXTRACT (MICROSECOND FROM '2003-01-02 10:30:10.00123');
Chris
From: | Michael Fuhr <mike(at)fuhr(dot)org> |
---|---|
To: | Christopher Kings-Lynne <chriskl(at)familyhealth(dot)com(dot)au> |
Cc: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Oddity with extract microseconds? |
Date: | 2005-12-07 02:22:01 |
Message-ID: | 20051207022201.GA60740@winnie.fuhr.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
On Wed, Dec 07, 2005 at 09:43:30AM +0800, Christopher Kings-Lynne wrote:
> >>Why aren't 'minutes' considered too? Because they aren't 'seconds'.
> >>Well, seconds aren't microseconds either.
> >
> >Yeah, they are: it's just one field. The other way of looking at it
> >(that everything is seconds) is served by "extract(epoch)".
>
> Well, it's different in MySQL unfortunately - what does the standard
> say?
I don't see microseconds as a possible field in SQL:2003 (draft copy).
> Out of interest, can someone try this for me in MySQL 5:
>
> SELECT EXTRACT (MICROSECOND FROM '2003-01-02 10:30:00.00123');
> SELECT EXTRACT (MICROSECOND FROM '2003-01-02 10:30:10.00123');
MySQL 5.0.16 gives an error:
mysql> SELECT EXTRACT (MICROSECOND FROM '2003-01-02 10:30:00.00123');
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual
that corresponds to your MySQL server version for the right syntax to use
near 'FROM '2003-01-02 10:30:00.00123')' at line 1
--
Michael Fuhr
From: | Christopher Kings-Lynne <chriskl(at)familyhealth(dot)com(dot)au> |
---|---|
To: | Michael Fuhr <mike(at)fuhr(dot)org> |
Cc: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Oddity with extract microseconds? |
Date: | 2005-12-07 02:32:20 |
Message-ID: | 439649B4.2060209@familyhealth.com.au |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
> MySQL 5.0.16 gives an error:
>
> mysql> SELECT EXTRACT (MICROSECOND FROM '2003-01-02 10:30:00.00123');
> ERROR 1064 (42000): You have an error in your SQL syntax; check the manual
> that corresponds to your MySQL server version for the right syntax to use
> near 'FROM '2003-01-02 10:30:00.00123')' at line 1
Odd, that example is straight from the MySQL 5 manual:
http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html
Chris
From: | Michael Fuhr <mike(at)fuhr(dot)org> |
---|---|
To: | Christopher Kings-Lynne <chriskl(at)familyhealth(dot)com(dot)au> |
Cc: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Oddity with extract microseconds? |
Date: | 2005-12-07 02:41:54 |
Message-ID: | 20051207024154.GA60917@winnie.fuhr.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
On Wed, Dec 07, 2005 at 10:32:20AM +0800, Christopher Kings-Lynne wrote:
> >MySQL 5.0.16 gives an error:
> >
> >mysql> SELECT EXTRACT (MICROSECOND FROM '2003-01-02 10:30:00.00123');
> >ERROR 1064 (42000): You have an error in your SQL syntax; check the manual
> >that corresponds to your MySQL server version for the right syntax to use
> >near 'FROM '2003-01-02 10:30:00.00123')' at line 1
>
> Odd, that example is straight from the MySQL 5 manual:
>
> http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html
Looks like MySQL doesn't allow a space before the open parenthesis
(there isn't one in the manual's example):
mysql> SELECT EXTRACT(MICROSECOND FROM '2003-01-02 10:30:00.00123');
+-------------------------------------------------------+
| EXTRACT(MICROSECOND FROM '2003-01-02 10:30:00.00123') |
+-------------------------------------------------------+
| 1230 |
+-------------------------------------------------------+
1 row in set (0.01 sec)
--
Michael Fuhr
From: | Christopher Kings-Lynne <chriskl(at)familyhealth(dot)com(dot)au> |
---|---|
To: | Michael Fuhr <mike(at)fuhr(dot)org> |
Cc: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Oddity with extract microseconds? |
Date: | 2005-12-07 02:47:45 |
Message-ID: | 43964D51.6050707@familyhealth.com.au |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
> Looks like MySQL doesn't allow a space before the open parenthesis
> (there isn't one in the manual's example):
>
> mysql> SELECT EXTRACT(MICROSECOND FROM '2003-01-02 10:30:00.00123');
> +-------------------------------------------------------+
> | EXTRACT(MICROSECOND FROM '2003-01-02 10:30:00.00123') |
> +-------------------------------------------------------+
> | 1230 |
> +-------------------------------------------------------+
> 1 row in set (0.01 sec)
Ok, and what does this give:
SELECT EXTRACT(MICROSECOND FROM '2003-01-02 10:30:01.00123');
Chris
From: | Michael Fuhr <mike(at)fuhr(dot)org> |
---|---|
To: | Christopher Kings-Lynne <chriskl(at)familyhealth(dot)com(dot)au> |
Cc: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Oddity with extract microseconds? |
Date: | 2005-12-07 02:53:37 |
Message-ID: | 20051207025337.GA61048@winnie.fuhr.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
On Wed, Dec 07, 2005 at 10:47:45AM +0800, Christopher Kings-Lynne wrote:
> Ok, and what does this give:
>
> SELECT EXTRACT(MICROSECOND FROM '2003-01-02 10:30:01.00123');
mysql> SELECT EXTRACT(MICROSECOND FROM '2003-01-02 10:30:01.00123');
+-------------------------------------------------------+
| EXTRACT(MICROSECOND FROM '2003-01-02 10:30:01.00123') |
+-------------------------------------------------------+
| 1230 |
+-------------------------------------------------------+
1 row in set (0.00 sec)
Does contrary behavior from MySQL count as evidence that PostgreSQL's
behavior is correct? :-)
--
Michael Fuhr
From: | Christopher Kings-Lynne <chriskl(at)familyhealth(dot)com(dot)au> |
---|---|
To: | Michael Fuhr <mike(at)fuhr(dot)org> |
Cc: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Oddity with extract microseconds? |
Date: | 2005-12-07 03:03:13 |
Message-ID: | 439650F1.4050901@familyhealth.com.au |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
> mysql> SELECT EXTRACT(MICROSECOND FROM '2003-01-02 10:30:01.00123');
> +-------------------------------------------------------+
> | EXTRACT(MICROSECOND FROM '2003-01-02 10:30:01.00123') |
> +-------------------------------------------------------+
> | 1230 |
> +-------------------------------------------------------+
> 1 row in set (0.00 sec)
>
> Does contrary behavior from MySQL count as evidence that PostgreSQL's
> behavior is correct? :-)
No...I happen to think that their way is more consistent though. Pity
it's not in the spec.
At least PostgreSQL is consistent with seconds/microseconds:
mysql=# select extract(seconds from timestamp '2005-01-01 00:00:01.01');
date_part
-----------
1.01
(1 row)
Chris
From: | Harald Fuchs <hf0923x(at)protecting(dot)net> |
---|---|
To: | pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: Oddity with extract microseconds? |
Date: | 2005-12-07 09:23:13 |
Message-ID: | 87bqztxnum.fsf@srv.protecting.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
In article <439650F1(dot)4050901(at)familyhealth(dot)com(dot)au>,
Christopher Kings-Lynne <chriskl(at)familyhealth(dot)com(dot)au> writes:
mysql> SELECT EXTRACT(MICROSECOND FROM '2003-01-02 10:30:01.00123');
>> +-------------------------------------------------------+
>> | EXTRACT(MICROSECOND FROM '2003-01-02 10:30:01.00123') |
>> +-------------------------------------------------------+
>> | 1230 |
>> +-------------------------------------------------------+
>> 1 row in set (0.00 sec)
>> Does contrary behavior from MySQL count as evidence that PostgreSQL's
>> behavior is correct? :-)
> No...I happen to think that their way is more consistent though. Pity
> it's not in the spec.
I'd say the comparison with MySQL is useless because MySQL is unable
to store microseconds in a DATETIME or TIMESTAMP column, although you
can extract microseconds from a date/time literal.
From: | Andrew Dunstan <andrew(at)dunslane(dot)net> |
---|---|
To: | Christopher Kings-Lynne <chriskl(at)familyhealth(dot)com(dot)au> |
Cc: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Oddity with extract microseconds? |
Date: | 2005-12-07 15:37:19 |
Message-ID: | 439701AF.1060202@dunslane.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
Christopher Kings-Lynne wrote:
>>> Why aren't 'minutes' considered too? Because they aren't 'seconds'.
>>> Well, seconds aren't microseconds either.
>>
>>
>> Yeah, they are: it's just one field. The other way of looking at it
>> (that everything is seconds) is served by "extract(epoch)".
>
>
> Well, it's different in MySQL unfortunately - what does the standard
> say? Out of interest, can someone try this for me in MySQL 5:
>
> SELECT EXTRACT (MICROSECOND FROM '2003-01-02 10:30:00.00123');
> SELECT EXTRACT (MICROSECOND FROM '2003-01-02 10:30:10.00123');
mysql 4.1.5 gives back 123 in both cases. I assume they haven't changed
that, although anything is possible.
cheers
andrew