小编at.*_*at.的帖子

如何在PostgreSQL中将没有时区的时间转换为没有时区的时间戳?

我在试图改变类型的列时,这个错误time类型为timestamp

PG::CannotCoerce: ERROR:  cannot cast type time without time zone to timestamp without time zone
Run Code Online (Sandbox Code Playgroud)

现有时间如何转换对我来说并不重要,但我确实需要更改此列。我怎么能强制这个或投这个?

这是 SQL 语句:

ALTER TABLE "students" ALTER COLUMN "time_since_missing_schedule_notification" TYPE timestamp USING CAST(time_since_missing_schedule_notification AS timestamp)
Run Code Online (Sandbox Code Playgroud)

我正在使用 Rails/ActiveRecord,这是生成上述 SQL 语句的 Ruby 代码:

change_column :students, :time_since_missing_schedule_notification, 'timestamp USING CAST(time_since_missing_schedule_notification AS timestamp without time zone)'
Run Code Online (Sandbox Code Playgroud)

当我连接到 Heroku 的 PostgreSQL 服务器时,我得到以下版本:

psql (9.3.1, server 9.2.7)
Run Code Online (Sandbox Code Playgroud)

postgresql cast heroku postgresql-9.3 rails

5
推荐指数
1
解决办法
2万
查看次数

标签 统计

cast ×1

heroku ×1

postgresql ×1

postgresql-9.3 ×1

rails ×1