ruby - 默认 : "now()" in Sequel generates literal embedded into the defenitiion of a table

标签 ruby postgresql sequel

我正在尝试在 Sequel 中创建一个默认值:

create_table(:my_table) do
  primary_key :id
  # ..........
  Timestamp :created_at, default: "now()"

运行迁移后,它会生成一个包含此列定义的表:

  --........
  created_at timestamp without time zone DEFAULT '2017-10-28 12:26:00.129157'::timestamp without time zone,

但我想要的是在插入新值时设置的值“now()”。

最佳答案

我知道不久前有人问过这个问题,但我遇到了一个类似的问题,我使用 Sequal.lit

解决了这个问题

时间戳:created_at,默认:Sequel.lit("now()")

关于ruby - 默认 : "now()" in Sequel generates literal embedded into the defenitiion of a table,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46986793/

相关文章:

ruby - Sequel模型过滤多对多关系

ruby - 在 ruby​​ 中的字符串前后添加空格?

mysql - 如何添加 UNIQUE AUTO_INCREMENT FIRST id 列

ruby - sidekiq 应用程序中的 postgres 编码错误

postgresql - 是否可以在形式为 'create materialized view as' 的物化 View 上创建新索引?

java - JBAS010441 : Failed to load module for driver [org. postgresql]

postgresql - SPI 与 PLPGSQL 的性能对比

ruby - 如何在 Rack::Builder::map 中使用 Lotus 路由器

ruby-on-rails - Ruby on Rails/Paperclip Gem : Does not resize images, 似乎只保存 'original' 图像

ruby-on-rails - Rails 4 ActiveRecord::StatementInvalid