Reputation: 31
I'm trying to create a default value in Sequel:
create_table(:my_table) do
primary_key :id
# ..........
Timestamp :created_at, default: "now()"
After running a migration, it generates a table with this column definition:
--........
created_at timestamp without time zone DEFAULT '2017-10-28 12:26:00.129157'::timestamp without time zone,
But what I want is the value "now()" to be set when I'm inserting a new value.
Upvotes: 1
Views: 1020
Reputation: 14900
The way to do it is as follows, using either Sequel.function(:now)
or Sequel::CURRENT_TIMESTAMP
Time :created_at, default: Sequel.function(:now)
# or...
Time :created_at, default: Sequel::CURRENT_TIMESTAMP
Upvotes: 0
Reputation: 21
I know this was asked a while ago but I had a similar problem that I solved by using Sequal.lit
Timestamp :created_at, default: Sequel.lit("now()")
Upvotes: 2
Reputation: 8478
Are you trying to set a String in a Time field? I don't think this is going to work. You'll have to use String :created_at, default: "now()"
Upvotes: 0