title: Rails misbehaving wrt Postgres SERIAL NOT NULL column
body: <p>I am developing a (currently) Rails 2.3.x application with a PostgreSQL 8.4 database backend. In my Rails application, I have a model corresponding to a database table that has two columns of datatype SERIAL and set as NOT NULL.  I have one of these columns set as the primary key in both Rails and as a PostgreSQL constraint.</p>
  
  <p>Table definition:</p>
  
  <pre><code>CREATE TABLE problem_table
  (
    col1 serial NOT NULL,
    col2 serial NOT NULL,
    other_col1 character varying,
    other_col2 character varying,
    ...,
    CONSTRAINT problem_table_pkey PRIMARY KEY (col1)
  );
  </code></pre>
  
  <p>Model class definition:</p>
  
  <pre><code>class ModelClass1 &lt; ActiveRecord::Base
    self.table_name = 'problem_table'
    self.primary_key = 'col1'
  end
  </code></pre>
  
  <p>My problem is with respect to the non-primary-key SERIAL NOT NULL column.  When I try to do a Rails ActiveRecord::Base#create, Rails rightly doesn't set a value for the primary key SERIAL NOT NULL column, but sets a column value of NULL for the other one, which causes PostgreSQL to complain that the NOT NULL column is being set to NULL.</p>
  
  <p>What I tell Rails to do:</p>
  
  <pre><code>ModelClass1.create(
    other_col1: 'normal'
    other_col2: 'data',
    ...
  );
  </code></pre>
  
  <p>What Rails tells PostgreSQL:</p>
  
  <pre><code>INSERT INTO problem_table (
    col2, 
    other_col1, 
    other_col2,
    ...
  ) VALUES (
    NULL,
    'normal',
    'data',
    ...
  );
  </code></pre>
  
  <p>My question is, how can I get Rails to stop passing NULL for this column and just not pass anything, letting the DEFAULT nextval(my_seq) take over?  Or, if that is not possible, how can I tell PostgreSQL to ignore this NULL value when passed and/or recognize this to be the same as 'set as DEFAULT'?</p>
  
  <p>I would try to just monkey patch Rails 2.3.x ActiveRecord internals, but I know if I did so I'd be screwed when it came to transitioning to Rails 3.</p>
  
  <p>I've looked into trying to fix things with a PL/pgSQL trigger BEFORE INSERT, but I can't figure out how to tell PostgreSQL with PL/pgSQL to 'undefine' the NEW.col2 value or say NEW.col2 := DEFAULT (which does not work).</p>
  
  <p>Answers and/or suggestions are appreciated!</p>