How to handle bogus nulls from ActiveRecord

From: "James B(dot) Byrne" <byrnejb(at)harte-lyne(dot)ca>
To: pgsql-general(at)postgresql(dot)org
Subject: How to handle bogus nulls from ActiveRecord
Date: 2011-05-12 13:12:08
Message-ID: 34084.216.185.71.25.1305205928.squirrel@webmail.harte-lyne.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

It is required for application data verification filters that
default values for table columns are known to ActiveRecord when
creating a new row. So ActiveRecord obtains the default values from
the tables dynamically and assigns them to their appropriate column
attributes. The problem we encounter arises because ActiveRecord
then uses those column assignments when inserting a row even if the
column is not otherwise referenced.

I am developing a web application using the Ruby on Rails framework
with PostgreSQL as the back-end store. In one of our tables we have
a column called expected_by which is a time-stamp. It is set to NOT
NULL DEFAULT 'INFINITY'. However, Ruby has no concept of infinity
and whatever the PostgreSQL adapter is returning for it ActiveRecord
receives as nil which is converted to NULL.

So, the real fix to this is to alter the persistence class so that
columns with default values are not explicitly set to those values
on insert. This is unlikely to happen in the short term and will
take some time to be integrated into the framework even when it is
completed, if ever,

So solve this for the moment what I think I require is a trigger on
expected_at which tests for NULL on insert and converts it to
infinity. The other alternative is to simply set the default to
some valid, but unreachable, date like 9999-12-31.

I would like other opinions about how to best handle this situation
and observations on what other significant concerns I may not be
aware of but should provide for.

--
*** E-Mail is NOT a SECURE channel ***
James B. Byrne mailto:ByrneJB(at)Harte-Lyne(dot)ca
Harte & Lyne Limited http://www.harte-lyne.ca
9 Brockley Drive vox: +1 905 561 1241
Hamilton, Ontario fax: +1 905 561 0757
Canada L8E 3C3

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Marek Więckowski 2011-05-12 13:58:19 Re: auto-reconnect: temp schemas, sequences, transactions
Previous Message hubert depesz lubaczewski 2011-05-12 11:19:45 Re: vacuumdb with cronjob needs password since 9.0?