Re: NULL value vs. DEFAULT value.

From: "James B(dot) Byrne" <byrnejb(at)harte-lyne(dot)ca>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: NULL value vs. DEFAULT value.
Date: 2011-03-08 16:42:59
Message-ID: 48168.216.185.71.25.1299602579.squirrel@webmail.harte-lyne.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


On Tue, March 8, 2011 10:09, Scott Ribe wrote:
> On Mar 8, 2011, at 7:54 AM, James B. Byrne wrote:
>
>> My question is: Why am I getting a NULL exception?
>
> Because you're trying to insert NULL explicitly?

Yes, that is the problem. Evidently RoR's ActiveRecord helpfully
converts a string containing nought but spaces to nil when a numeric
value is required for the column type. The problem arises with a
single unit record received from the government system that has a
UOM code provided but the associated decimal value field is blank.

Since the default is zero in our DB I have altered our load program
to coerce a value of zero for strings containing only spaces
destined for numeric columns. But, it feels ugly. I would really
like to be able to coerce nils to some value on a column by column
basis on the DBMS side. This is not really a DEFAULT value and I do
not know what I would call it if such a thing did exist. I suppose
a trigger and function is called for.

Thanks for the help.

--
*** 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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Joshua D. Drake 2011-03-08 16:57:24 #PgEast schedule is up
Previous Message David Johnston 2011-03-08 15:45:41 Re: NULL value vs. DEFAULT value.