我需要對我的數據庫執行一些日期時間操作,這需要所有created
時間戳具有相同的年份。我試圖與此查詢:PostgreSQL中的時間戳操作 - 帶小時/時區的問題
select created,cast (created -
to_timestamp(''||date_part('year', created), 'YYYY') +
timestamp '2010-01-01' as timestamp without time zone)
from table where created is not null limit 10;
...但結果是隻能部分滿足:
created | timestamp
---------------------+---------------------
2010-08-29 12:44:05 | 2010-08-29 11:44:05
2007-06-21 13:49:22 | 2010-06-21 12:49:22
2007-06-21 15:02:33 | 2010-06-21 14:02:33
2007-06-21 15:05:26 | 2010-06-21 14:05:26
1999-09-30 13:00:00 | 2010-09-30 12:00:00
1997-06-07 13:00:00 | 2010-06-07 12:00:00
2010-06-15 20:51:01 | 2010-06-15 19:51:01
2006-08-26 15:33:02 | 2010-08-26 14:33:02
2009-12-15 11:07:06 | 2010-12-15 11:07:06
1997-06-28 13:00:00 | 2010-06-28 12:00:00
(10 rows)
正如你所看到的,所有的時間戳是-1小時比較原始created
值。更奇怪的是,最後一個(2010-12-15 11:07:06
)之前沒有。
created
列是timestamp without time zone
類型。
任何想法我做錯了什麼?