whimsycl has asked for the wisdom of the Perl Monks concerning the following question:

I have written a script whose end task is to insert data into a postgreSQL database. I am having trouble trying to insert a null date value when the field type is date and there is no date listed in that record's field. I've tried to construct an if/else statement, but the word null seems to wreck things. I tried using undef and the script did not run using it.

I've tried it this way (including omitting the length):

$flds[6] = (length($flds[6]) == 0) ? 'NULL';"\'$flds[6]\'";

and I've also tried it this way (including adding length):

if ($flds[6] eq '') { $flds[6] = NULL; } else { $flds[6] = $flds[6]; }

My error message either says bad external date representation or there is a syntax error near null. I've tried changing the quotes around and using upper and lowercase letters.

Any help would be greatly appreciated. Please let me know if I haven't provided enough information

Replies are listed 'Best First'.
•Re: perl, postgreSQL, and null dates
by merlyn (Sage) on Apr 15, 2003 at 19:53 UTC
    If you're using placeholders, an undef field represents a NULL. Otherwise, when you are saying NULL, you're getting the string NULL, which last I checked is not a valid date. {grin}

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.