使用to_date更改数据格式不会更改位数(postgresql)
我正在尝试将列“yearcode”的日期格式更改为四位数字(yyyy),因为我没有数据的具体日期 但是,当我检查列的数据格式时,该表仍然以“yyyy-mm-dd”格式显示日期格式 以下是我为更改格式而编写的代码:使用to_date更改数据格式不会更改位数(postgresql),sql,postgresql,date,format,dataformat,Sql,Postgresql,Date,Format,Dataformat,我正在尝试将列“yearcode”的日期格式更改为四位数字(yyyy),因为我没有数据的具体日期 但是,当我检查列的数据格式时,该表仍然以“yyyy-mm-dd”格式显示日期格式 以下是我为更改格式而编写的代码: alter table postmaster_compensation alter yearcode type date using to_date('1845','yyyy') 我想知道代码是否有问题,或者我根本无法将格式更改为“yyyy”模式?9.6参考说明“yyyy”是有效的日
alter table postmaster_compensation alter yearcode type date using to_date('1845','yyyy')
我想知道代码是否有问题,或者我根本无法将格式更改为“yyyy”模式?9.6参考说明“yyyy”是有效的日期格式
谢谢 如果该列应为char,则将该列的格式更改为char,并获取使用的年份以_char
alter table postmaster_compensation alter yearcode type char(4) using to_char('01/01/1845','yyyy')
如果列应为int,则将列的格式更改为int,并从日期提取年份
alter table postmaster_compensation alter yearcode type int using extract(year from '01/01/1845','yyyy')
截止日期('1845','yyyy')
给出的是“1845-01-01”,而不是“1845”