Forum: Ruby Sequel: Cannot save model or limit varchars

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Florian Aßmann (Guest)
on 2007-06-05 02:10
(Received via mailing list)
Hi out there,

I experienced Problems when I tried to save a Sequel::Model

   ERROR database: ERROR:  currval of sequence "schedules_id_seq" is
not yet defined in this session

The model schema is:

   set_schema do
     serial    :id, :primary_key => true
     varchar   :state, :default => 'running'

     timestamp :starts_at
     timestamp :stops_at

     integer   :aberrate_with
     integer   :dispersal_shift

During testing I always recreate the models table.

Also I cant figure out how to limit varchars...

Florian Aßmann (Guest)
on 2007-06-05 04:01
(Received via mailing list)
Huh, did some hacking... to fix this problem I changed the sequel/
postgres.rb code a bit:


   # See:
   RETURNING = " RETURNING (%s)".freeze

   # Initializes and returns @table_sequence
   def table_sequences
     # define default procedure for missing keys (tables) that
fetches the pkey
     @table_sequences ||= do |sequences, table|
       # this is not threadsafe but the results shouldn't differ
       @pool.hold { |conn| sequences[table] = conn.pkey_and_sequence
(table).first }
   # Ahh, protect this Method... *paranoia*
   protected :table_sequences

   def execute_insert(sql, table)
     # add RETURNING statement to sql
     sql << RETURNING % table_sequences[table] if @logger

     # this is not nice :(
     @pool.hold do |conn|
       result = conn.execute sql
       id = result[0][0].to_i and result.clear


   rescue => e
     @logger.error(e.message) if @logger
     raise e


@L1: I'd replace:

   if !Object.const_defined?('Sequel')
     require File.join(File.dirname(__FILE__), '../sequel')


   require File.join(File.dirname(__FILE__), '../sequel')

since Ruby itself checks whether a file is already required...

Another question:
Is PGconn the right place for the @table_sequences cache? I'd place
it in the Sequel::Postgres module...


Am 05.06.2007 um 00:09 schrieb Florian Aßmann:
Sam S. (Guest)
on 2007-06-05 06:32
(Received via mailing list)
On Jun 4, 7:01 pm, Florian Aßmann <removed_email_address@domain.invalid> wrote:
>      # define default procedure for missing keys (tables) that
> Another question:
> > I experienced Problems when I tried to save a Sequel::Model
> >     timestamp :starts_at
> > Sincerely
> > Florian

Not that I mind, but you mind get a better response on the Sequel
mailing list:
This topic is locked and can not be replied to.