Postgres 中的 RR MILLENNIUM 等价物

RR MILLENNIUM equivalent in Postgres

PostgreSQL 9.5 版本中是否有内置函数来计算合适的century/millenium?

当我使用 table 中的 birth_date::TIMESTAMP 时,有时它以 19 为前缀,有时以 20 为前缀。下面的示例

输入:

28JUN80  
25APR48

输出:

"1980-06-28 00:00:00"  
"2048-04-25 00:00:00"

我在 table 中也有记录,其中 birth_date 保存值如“07APR1963”,它被适当地计算为“1963-04-07 00:00:00”。

我需要在长度为7个字符时使用CASE语句,然后加上19个千禧年前缀,当它的长度为9个字符时,直接加载它就可以了。

https://en.wikipedia.org/wiki/Unix_time Unix 纪元是

beginning (00:00:00 1 January 1970)

因此,如果您不指定世纪,而只指定最后一个 YY,则 00:00:00 1 January 为 20 世纪,YY 之前为 21 世纪,等于 70。如果你想让它猜测 20 世纪,要么像你一样追加年份,要么指定 CC,例如:

t=> select 
  to_timestamp('1JAN70', 'ddmonYY')
, to_timestamp('31DEC69', 'ddmonyy')
, to_timestamp('31DEC69 20', 'ddmonyy cc');
      to_timestamp      |      to_timestamp      |      to_timestamp
------------------------+------------------------+------------------------
 1970-01-01 00:00:00+00 | 2069-12-31 00:00:00+00 | 1969-12-31 00:00:00+00
(1 row)

https://www.postgresql.org/docs/current/static/functions-formatting.html

In conversions from string to timestamp or date, the CC (century) field is ignored if there is a YYY, YYYY or Y,YYY field. If CC is used with YY or Y then the year is computed as the year in the specified century. If the century is specified but the year is not, the first year of the century is assumed.

更新

所以在你的情况下你应该这样做:

vao=# create table arasu (member_birth_date character(9)); insert into arasu values ('28JUN80'),('25APR48');
CREATE TABLE
INSERT 0 2
vao=# select to_timestamp(member_birth_date||' 20', 'ddmonYY cc') from arasu;
      to_timestamp
------------------------
 1980-06-28 00:00:00+03
 1948-04-25 00:00:00+03
(2 rows)