Thank you. Seeing that Sequel is an ORM, it might have taken into account the database type and incorporated that into its methods. But I guess it is not. I've been over that page many times. In this case, I was looking for *now()*, which was postgresql specific.
Cheers On Friday, October 15, 2021 at 8:23:30 PM UTC-4 Jeremy Evans wrote: > On Fri, Oct 15, 2021 at 4:46 PM [email protected] <[email protected]> wrote: > >> A couple of things. I'm looking for a way to create a timestamp field >> that has a default expression of *now().* >> >> Documentation shows the following, whose first field is tripping: >> >> *DL.create_table(:bubbbles) do* >> * column :a1, :string # error below* >> * column :a2, String * >> * column :a3, 'string' * >> * column :a4, :datetime * >> * column :a5, DateTime * >> * column :a6, 'timestamp(6)' * >> *end* >> >> *PG::UndefinedObject: ERROR: type "string" does not exist >> (Sequel::DatabaseError)* >> *LINE 1: CREATE TABLE "bubbbles" ("a1" string, "a2" text, "a3" string...* >> >> I guess the docs have a slight error. Second, how can I get that field >> to take that expression as the default? >> > > The docs don't have an error. They document the type used, which you > chose to omit. Here's the example taken from the schema modification guide: > > create_table(:columns_types) do # database type used > column :a1, :string # string > column :a2, String # varchar(255) > column :a3, 'string' # string > column :a4, :datetime # datetime > column :a5, DateTime # timestamp > column :a6, 'timestamp(6)' # timestamp(6) > end > > In your case, you get text instead of varchar(255) for String, because > that's a generic type and Sequel uses text instead of varchar(255) on > PostgreSQL (as text is the recommended type to use for strings on > PostgreSQL). You get an error in the query because "string" is not a valid > database type on PostgreSQL. The documentation is meant to serve as an > example for understanding how Sequel works, it is not meant to be blindly > copied and pasted. You may want to read the entire section on column > types: > http://sequel.jeremyevans.net/rdoc/files/doc/schema_modification_rdoc.html#label-Column+types > > You probably want to use the default: Sequel::CURRENT_TIMESTAMP option to > set the default value for the column. > > Thanks, > Jeremy > -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/sequel-talk/592f2953-c977-4ee9-bf1b-e0cefe9613e4n%40googlegroups.com.
