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/CADGZSSdBrR_o%3DbFHPLM9%3D9mmjwvdHitYdnSgVXpPA%3DagkLhbjA%40mail.gmail.com.

Reply via email to