El Martes, 19 de Enero de 2010, Iñaki Baz Castillo escribió:
> Hi, I need two columns in tables of MySQL/Postgres:
>
> - "created" (timestamp/datetime)
> - "last_modified" (timestamp/datetime)
>
> I want to avoid doing it with Ruby ("table[:created] = Time.now" and so) as
> I expect it's much faster if we let this job for the database itself.
>
> How could I tell Sequel to create a column datetime column with default
> value "NOW()"? Of course the following doesn't work:
>
> column :modified, DateTime, :default => "NOW()"
>
> Also I need it working for MySQL and Postgres.
>
> Obviously "created" must be set to NOW() by the database when creating the
> row, and "last_modified" must be set to NOW() by the database when updating
> it.
>
> Is it possible with Sequel::Schema::Generator ?
I've also tryed with:
column :modified, DateTime, :default => Sequel::SQL::Function.new(:now)
and:
column :modified, DateTime, :default => :now.sql_function
but no luck, it raises an error:
"Sequel::DatabaseError: Mysql::Error: Invalid default value for 'modified'"
--
Iñaki Baz Castillo <[email protected]>
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sequel-talk?hl=en.