paulbort has asked for the wisdom of the Perl Monks concerning the following question:
I'm quite happy with DBI except one gaping hole, and I am hoping that someone has a solution for this. I would like to prepare an SQL UPDATE statement, and be able to pass undef as a parameter when I execute that statement, and have the underlying database (PostgreSQL) set that field to NULL. It seems a reasonable request, given that a SELECT will return a NULL field as undef.
I've searched and super-searched, and read through the docs in perldoc and CPAN, and only found one good match: 137005 suggests using '' (empty string) instead of undef, but '' and NULL are different values.
I know I can construct an UPDATE statement and $dbh->do() it, but a prepared statement makes for much more readable code, IMHO.
Any ideas? I would be very happy to find that I'm missing something obvious.
UPDATE: Problem Solved. PEBCAK (Problem Exists Between Chair And Keyboard.) Once I reduced the update to one column , the undef to NULL mapping works for that column, so one of my other columns is doing something stupid. Thanks to all who helped.
--
Spring: Forces, Coiled Again!
I've searched and super-searched, and read through the docs in perldoc and CPAN, and only found one good match: 137005 suggests using '' (empty string) instead of undef, but '' and NULL are different values.
I know I can construct an UPDATE statement and $dbh->do() it, but a prepared statement makes for much more readable code, IMHO.
Any ideas? I would be very happy to find that I'm missing something obvious.
UPDATE: Problem Solved. PEBCAK (Problem Exists Between Chair And Keyboard.) Once I reduced the update to one column , the undef to NULL mapping works for that column, so one of my other columns is doing something stupid. Thanks to all who helped.
--
Spring: Forces, Coiled Again!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: DBI Prepared Update and NULLs
by diotalevi (Canon) on Jul 28, 2004 at 20:00 UTC | |
by paulbort (Hermit) on Jul 28, 2004 at 20:53 UTC | |
by iburrell (Chaplain) on Jul 28, 2004 at 21:09 UTC | |
Re: DBI Prepared Update and NULLs
by gaal (Parson) on Jul 28, 2004 at 20:04 UTC | |
by iburrell (Chaplain) on Jul 28, 2004 at 20:55 UTC | |
Re: DBI Prepared Update and NULLs
by lhoward (Vicar) on Jul 28, 2004 at 20:09 UTC | |
by paulbort (Hermit) on Jul 28, 2004 at 20:58 UTC |
Back to
Seekers of Perl Wisdom