Postgres 时间戳到 DATE dd-mm-yyyy

Postgres Timestamp to DATE dd-mm-yyyy

我正在尝试在日期列时间戳中插入 select 铸造时间戳,例如 02-09-2021 00:00:00,我需要将此时间戳转换为日期 dd-mm-yyyy 而不使用 hhmmss ,我试过 select date(column) as newdate 但是当我检查我的 table 插入时,它保持像时间戳一样,我尝试的所有解决方案只能在 select 中完美运行句子,但是当我尝试插入 select.. 我保持时间戳类型..

如果您需要将格式化文本转换为 timestamp,则使用具有明确格式规范的 to_timestamp。试试这个:

select to_timestamp('02-09-2021 00:00:00', 'dd-mm-yyyy hh24:mi:ss');
to_timestamp
2021-02-09 00:00:00.000 +0200

将其转换为date:

select to_date('02-09-2021 00:00:00', 'dd-mm-yyyy');

如果您需要将现有 timestamp 列的类型更改为 date,则:

alter table the_table alter column the_column type date using the_column::date;