'1年'='360天'???? [英] '1 year' = '360 days' ????

查看:104
本文介绍了'1年'='360天'????的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好:


我是PostgreSQL的新手,现在正在使用日期,时间,时间戳和

的间隔。


我对上述问题有三个问题:


首先:

--------


我观察到,对于PostgreSQL,一年实际上是360天:


SELECT''1年'':: timestamp ='''360天'' :: timestamp;


?栏?

-------------

t

Glubs!我相信1年是365天,如果是飞跃则是366。这是正常的吗?

第二:

-----------


当我想检查时两个日期之间有多少时间,我有两个选项

(显示两个不同的结果):


SELECT''30 -09-04'' :: timestamp - '30 -09-03'':: timestamp,

age(''30-09-04'':: timestamp,''30 -09-03'': :时间戳);


?列? |年龄

-------------------------------

@ 366天| @ 1年

结果不同。如果我们比较两个结果:


SELECT('​​30 -09-04'':: timestamp - ''30 -09-03'':: timestamp)=

age(''30-09-04'':: timestamp,''30 -09-03'':: timestamp);

?列?

--------------

f

显然,它返回False,因为我在第一个问题中告诉,1年对于PostgreSQL来说是
360天。


问题是:这是正常的吗?这两种方法中的哪一种是正确的?

减去时间戳?或者使用年龄函数?

第三:

--------


正如我在第二个问题,当我这样做时:


SELECT''30 -09-04'':: timestamp - '30 -09-03'':: timestamp;


结果是:


?栏?

--------------

@ 366天


问题是:有没有办法正常化结果,

结果是:


@ 1年1天





我认为它更好(也更正确)@ 1年1天而不是@ 366

days。有没有办法实现这个目标?


感谢大家。


里卡多。


__________________________________________________ _______________
$ b $bHoróscopo,tarot,numerología... Escucha lo que te dicen los astros。
http://astrocentro.msn.es/

--------------------- ------(广播结束)---------------------------

提示1:订阅和取消订阅命令转到 ma*******@postgresql.org

解决方案

2004年10月22日星期五13:37:19 +0200,

Ricardo Perez Lopez< ri *** **@hotmail.com>写道:

大家好:

我是PostgreSQL的新手,现在正在使用日期,时间,时间戳和间隔。
关于上述问题我有三个问题:

首先:
--------

我观察到,对于PostgreSQL,一年是实际上是360天:


不,不是。间隔存储为月和秒。当

为时间戳添加间隔时,添加月份和添加秒数是以不同方式处理的。在某些情况下,月份部分将

转换为秒,并且在那种情况下,一个月被视为

长达30天。

SELECT''1 year'':: timestamp ='''360天'':: timestamp;

?专栏?
-------------
t $ / $
Glubs!我相信1年是365天,如果是飞跃则是366。这是正常的吗?

SECOND:
-----------

当我想查看两个日期之间的时间时,我有两个选项
(显示两个不同的结果):

SELECT''30 -09-04'':: timestamp - '30 -09-03'':: timestamp ,
年龄(''30-09-04'':: timestamp,''30 -09-03'':: timestamp);

?专栏? |年龄
-------------------------------
@ 366天| @ 1年

结果不同。如果我们比较两个结果:

SELECT('​​30 -09-04'':: timestamp - ''30 -09-03'':: timestamp)=
age( '30 -09-04'':: timestamp,'30 -09-03'':: timestamp);

?栏?
-------- ------
f

显然,它返回False,因为我在第一个问题中告诉我,1年是PostgreSQL的360天。


这不是真的原因。当你使用年龄时,你得到一个月份混合的间隔

和秒部分。如果你减去两个时间戳,那么你得到一个间隔

只需几秒钟。

问题是:这是正常的吗?这两种方法中的哪一种是正确的?要减去时间戳?或者使用年龄函数?

第三:
--------

正如我在第二个问题中所说,当我这样做时:选择''30 -09-04'':: timestamp - '30 -09-03'':: timestamp;

结果是:

?专栏?
--------------
@ 366天

问题是:有什么办法吗? ;正规化"结果,结果是:

@ 1年1天


使用年龄。如果你这样做,那就是内部区间的内容。

我不认为有一种简单的方法来输出间隔的价值

所以它看起来像那样。但是如果你在操作中使用它,那么你应该做你想做的事情。 (虽然您需要考虑是否需要在添加12个月之前或之后添加

日。)



我认为它更好(更正确)1年1天而不是@ 366
天。有没有办法实现这一目标?

感谢大家。

里卡多。

__________________________________________________ _______________
Horóscopo,tarot,numerología。 .. Escucha lo que te dicen los astros。
http://astrocentro.msn.es /

---------------------------(播出结束)----- ----------------------
提示1:订阅和取消订阅命令转到 ma ******* @ postgresql.org




------------ ---------------(播出结束)---------------------------

提示3:如果通过Usenet发布/阅读,请将相应的

subscribe-nomail命令发送到 ma ******* @ postgresql.org 这样你的

消息就可以干净地通过邮件列表


" Ricardo Perez Lopez" < RI ***** @ hotmail.com>写道:

我观察到,对于PostgreSQL,一年实际上是360天:
SELECT''1 year'':: timestamp ='''360 days'':: timestamp;
?栏?
-------------
t




废话。


regression = #SELECT''1年'':: timestamp ='''360天'':: timestamp;

错误:类型timestamp的输入语法无效: 1年


如何告诉我们你真正*做了什么,而不是张贴伪造的

例子?


有些情况下,间隔(不是时间戳)1 / b
月将被视为相当于30天,因为缺少任何更好的

想法,但事实并非如此,Postgres并不知道其中的区别。


问候,tom lane


- -------------------------(播出结束)-------------------- -------

提示5:您查看了我们广泛的常见问题解答吗?

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


<集团kquote> Tom Lane< tg *@sss.pgh.pa.us>写道:

" Ricardo Perez Lopez" < RI ***** @ hotmail.com>写道:

我观察到,对于PostgreSQL,一年实际上是360天:


SELECT''1 year'':: timestamp ='''360天'':: timestamp;


?column?
-------------
t



废话。

regression = #SELECT''1 year'':: timestamp ='''360天'':: timestamp; <错误:类型timestamp的输入语法无效:1年

如何告诉我们你真正*做了什么,而不是张贴伪造的
示例?




FWIW:


template1 = #select''1年'':: interval =''360天'':: interval;

?栏?

----------

t

(1行)


template1 = #select''1年'':: interval =''365天'':: interval;

?栏?

----------

f

(1行)


template1 =#select version();



------ -------------------------------------------------- -------------

在i686-pc-linux-gnu上的PostgreSQL 7.4.5,由GCC egcs-2.91.66编译

(1排)


-Doug


-------------------- -------(播出结束)---------------------------

提示3:如果通过Usenet发布/阅读,请发送适当的

subscribe-nomail命令到 ma **** ***@postgresql.org ,以便您的

消息可以干净地通过邮件列表


Hello everyone:

I''m a PostgreSQL newbie, working now with dates, times, timestamps and
intervals.

I have three questions about the above:

FIRST:
--------

I have observed that, for PostgreSQL, one year is actually 360 days:

SELECT ''1 year''::timestamp = ''360 days''::timestamp;

?column?
-------------
t
Glubs! I believed that 1 year is 365 days, or 366 if leap. Is it normal?
SECOND:
-----------

When I want to check how many time is between two dates, I have two options
(which shows two different results):

SELECT ''30-09-04''::timestamp - ''30-09-03''::timestamp,
age(''30-09-04''::timestamp, ''30-09-03''::timestamp);

?column? | age
-------------------------------
@ 366 days | @ 1 year
The results are different. If we compare the two results:

SELECT (''30-09-04''::timestamp - ''30-09-03''::timestamp) =
age(''30-09-04''::timestamp, ''30-09-03''::timestamp);
?column?
--------------
f
Obviously, it returns False, because I told in the first question, 1 year is
360 days for PostgreSQL.

The question is: is it normal? Which of the two methods is the correct? To
substract timestamps? Or to use the age function?
THIRD:
--------

As I told in the second question, when I do:

SELECT ''30-09-04''::timestamp - ''30-09-03''::timestamp;

the result is:

?column?
--------------
@ 366 days

The question is: is there any way to "normalize" the result, such that the
result was:

@ 1 year 1 day

?

I think it''s better (and more correct) "@ 1 year 1 day" rather than "@ 366
days". Is there any way to achieve that?

Thanks to all.

Ricardo.

__________________________________________________ _______________
Horóscopo, tarot, numerología... Escucha lo que te dicen los astros.
http://astrocentro.msn.es/
---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

解决方案

On Fri, Oct 22, 2004 at 13:37:19 +0200,
Ricardo Perez Lopez <ri*****@hotmail.com> wrote:

Hello everyone:

I''m a PostgreSQL newbie, working now with dates, times, timestamps and
intervals.

I have three questions about the above:

FIRST:
--------

I have observed that, for PostgreSQL, one year is actually 360 days:
No it isn''t. The interval is stored as months and seconds. When
adding intervals to timestamps, adding months and adding seconds are
handled differently. Under some circumstances the months part gets
converted to seconds, and in that event a month is taken to be as
long as 30 days.
SELECT ''1 year''::timestamp = ''360 days''::timestamp;

?column?
-------------
t
Glubs! I believed that 1 year is 365 days, or 366 if leap. Is it normal?
SECOND:
-----------

When I want to check how many time is between two dates, I have two options
(which shows two different results):

SELECT ''30-09-04''::timestamp - ''30-09-03''::timestamp,
age(''30-09-04''::timestamp, ''30-09-03''::timestamp);

?column? | age
-------------------------------
@ 366 days | @ 1 year
The results are different. If we compare the two results:

SELECT (''30-09-04''::timestamp - ''30-09-03''::timestamp) =
age(''30-09-04''::timestamp, ''30-09-03''::timestamp);
?column?
--------------
f
Obviously, it returns False, because I told in the first question, 1 year
is 360 days for PostgreSQL.
That isn''t really why. When you use age you get an interval with a mix of month
and seconds parts. If you subtract two timestamps then you get an interval
with just a seconds part.

The question is: is it normal? Which of the two methods is the correct? To
substract timestamps? Or to use the age function?
THIRD:
--------

As I told in the second question, when I do:

SELECT ''30-09-04''::timestamp - ''30-09-03''::timestamp;

the result is:

?column?
--------------
@ 366 days

The question is: is there any way to "normalize" the result, such that the
result was:

@ 1 year 1 day
Use age. If you do that, that is what the interval will look like internally.
I don''t think there is an easy way to output the value of an interval
so that it looks like that. But if you use it in operations it should
do what you want. (Though you need to consider whether you want the
day added before or after you add the 12 months.)

?

I think it''s better (and more correct) "@ 1 year 1 day" rather than "@ 366
days". Is there any way to achieve that?

Thanks to all.

Ricardo.

__________________________________________________ _______________
Horóscopo, tarot, numerología... Escucha lo que te dicen los astros.
http://astrocentro.msn.es/
---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org



---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly


"Ricardo Perez Lopez" <ri*****@hotmail.com> writes:

I have observed that, for PostgreSQL, one year is actually 360 days: SELECT ''1 year''::timestamp = ''360 days''::timestamp; ?column?
-------------
t



Nonsense.

regression=# SELECT ''1 year''::timestamp = ''360 days''::timestamp;
ERROR: invalid input syntax for type timestamp: "1 year"

How about telling us what you *really* did, instead of posting faked
examples?

There are some contexts in which an interval (not a timestamp) of 1
month will be taken as equivalent to 30 days, for lack of any better
idea, but it''s not the case that Postgres doesn''t know the difference.

regards, tom lane

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

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


Tom Lane <tg*@sss.pgh.pa.us> writes:

"Ricardo Perez Lopez" <ri*****@hotmail.com> writes:

I have observed that, for PostgreSQL, one year is actually 360 days:


SELECT ''1 year''::timestamp = ''360 days''::timestamp;


?column?
-------------
t



Nonsense.

regression=# SELECT ''1 year''::timestamp = ''360 days''::timestamp;
ERROR: invalid input syntax for type timestamp: "1 year"

How about telling us what you *really* did, instead of posting faked
examples?



FWIW:

template1=# select ''1 year''::interval = ''360 days''::interval;
?column?
----------
t
(1 row)

template1=# select ''1 year''::interval = ''365 days''::interval;
?column?
----------
f
(1 row)

template1=# select version();
version
---------------------------------------------------------------------
PostgreSQL 7.4.5 on i686-pc-linux-gnu, compiled by GCC egcs-2.91.66
(1 row)

-Doug

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly


这篇关于'1年'='360天'????的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆