PostgreSQL - 错误:列“日期”无法转换为日期类型

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5967022/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-20 23:00:36  来源:igfitidea点击:

PostgreSQL - ERROR: column "date" cannot be cast to type date

postgresqldatecasting

提问by Athanasios Emmanouilidis

I want to cast a specific column in my PostgreSQL database from character_varying type to type date. phpPgAdmin gives me the following error:

我想将 PostgreSQL 数据库中的特定列从 character_variing 类型转换为日期类型。phpPgAdmin 给了我以下错误:

ERROR: column "date" cannot be cast to type date

In Statement: ALTER TABLE "public"."tablename" ALTER COLUMN "date" TYPE date

错误:无法将“日期”列强制转换为日期类型

在语句中:ALTER TABLE "public"."tablename" ALTER COLUMN "date" TYPE date

What should I do ? Thanks

我该怎么办 ?谢谢

回答by Denis de Bernardy

You might need to convert it to text first:

您可能需要先将其转换为文本:

alter table "foo" alter column "date" type date using ("date"::text::date);