【发布时间】:2020-03-29 23:29:14
【问题描述】:
我想创建下表。我是通过使用 ActiveRecord 运行 SQL 来实现的
alter table items add column sumup numeric generated always as ( quantity * price + (quantity * price* fpa/100) ) stored;
这是正确的做法吗?
def change
create_table :items do |t|
t.string :itemName
t.string :prom
t.string :promCode
t.string :baseCode
t.string :desc
t.numeric :fpa
t.numeric :price
t.integer :quantity
t.string :monadaMe
t.string :familys
t.timestamps
end
ActiveRecord::Base.connection.execute(" alter table items add column sumup numeric generated always as ( quantity * price + (quantity * price* fpa/100) ) stored;")
end
end
【问题讨论】:
-
欢迎来到 SO!请在 SO 上使用正确的语法。拼写、大写和标点符号很重要。有关详细信息,请参阅“How to Ask”和“Priority of grammar, spelling and punctuation in questions”。
标签: ruby-on-rails ruby postgresql