Nigel Metheringham wrote:
On 3 Apr 2008, at 16:30, Alex Povolotsky wrote:
Attempt to insert into postgres table with undef's for columns with
default values yields an error. It is especially bad with
find_or_create sub.
I've made and tested a simple patch, it looks working ok.
So the problem is that when you *explicitly* set column values to
undef (NULL), DBIC does not magically put default values in place?
Adding that (and the patch only touches Pg - thus making Pg behave
differently to all the other databases) appears like too much (or
inappropriate) magic to me.
I'd be happier with something that generically puts default values in
when the key/value to insert was missed out altogether, but in general
I tend to let the DB do that. At present it looks like default_value
is used only by deploy.
As far as I've understood the problem, it's because of "street SQL" used
by MySQL. For auto_increment fields, NULL on insert mean "insert next
key", the same as DEFAULT. However, it is against SQL standards. Since
DBIx::Class was, most likely, developed for MySQL, and tested on it,
that bug was missed.
find_or_create with primary key set to undef should create new record
properly, shouldn't it? Looks like patch must not fix Pg, but DBI in
general, setting DEFAULT value for unset columns with NOT NULL and DEFAULT.
Alex.
_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/[EMAIL PROTECTED]