Jiku
Jiku

Reputation: 31

default: "now()" in Sequel generates literal embedded into the defenitiion of a table

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

Answers (3)

Eyeslandic
Eyeslandic

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

Axl_Lind
Axl_Lind

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

three
three

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

Related Questions