Received: from fw1b.telekom.de (gw1.telekom.de [194.25.15.11]) by hub.org (8.9.3/8.9.3) with SMTP id CAA36347 for ; Wed, 17 May 2000 02:11:41 -0400 (EDT) (envelope-from Michael.Rudolph@telekom.de) Received: by fw1b.telekom.de; (5.65v4.0/1.3/10May95) id AA13184; Wed, 17 May 2000 08:11:39 +0200 Received: from G8PXB.blf01.telekom.de by U8PW4.blf01.telekom.de with ESMTP for pgsql-sql@postgresql.org; Wed, 17 May 2000 08:11:27 +0200 Received: from u8p11.blf01.telekom.de by G8PXB.blf01.telekom.de with ESMTP; Wed, 17 May 2000 08:11:24 +0200 Received: by U8P11.blf01.telekom.de with Internet Mail Service (5.5.2650.21) id ; Wed, 17 May 2000 08:11:23 +0200 Message-Id: From: "Rudolph, Michael" To: "'Michael A. Mayo'" , "'Alessio Bragadini'" Cc: pgsql-sql@postgresql.org Subject: AW: What is the difference between NULL and "undef" Date: Wed, 17 May 2000 08:11:22 +0200 Mime-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2650.21) Content-Type: text/plain; charset="iso-8859-1" X-Archive-Number: 200005/22 Ok, I see now, what mistakes in thinking I made. Thanks to all who informed me. But my original problem is not really solved, I just made a workaround and I'm not sure, if there is a real solution: I read in a date from an input-field of an formular. I now have to check, if this input-variable is empty. If it is, I set it to NULL, if not, I take it as input. My program looks now in parts like this: if ($var3 == 0){ $var3 = NULL } # Testing if empty else {$var3 = "'$var3'";} # input-field is not empty $rc = $dbh->do("INSERT INTO test1 (var1,var2,var3) VALUES ('$var1','$var2',$var3)"); with var3 being my date-variable. I have to juggle with the quotes to bring in the right value. If I wouldn't do the "'$var3'" in line 2, there were a parser error of Postgres. If I set the variable $var3 in line 5 in quotes, NULL wouldn't be interpreted in the right way. That solution works now, but it seems to me a bit fussy. And it is a lot of testing and transforming, when there are a lot of date- variables in the program. Michael >I believe you are confused about the meaning of "undef." In general, >variables are classified as undefined in one of 2 ways: >1) The variable is not declared, or is declared but no value is ever >assigned to it >2) The variable is assigned the return value of some function, and the >function fails, returning undef. > >A valid value is not "undef." Things like empty string or the number 0 are >valid values for a variable to have, and therefore are not "undef." Undef >should be interpreted as "something is catastrophically wrong with this >variable." > >CGI.pm returns an empty string for text form fields that are not filled out. >Therefore, it is neccecary to test for the empty string and translate that >to >NULL or undef if you want an empty form field to work out to NULL. > >---------------------------------------------------------------------------- >On my system, the following mini-program inserts a NULL value: >my $test_string; #note: no value assigned to test_string - it's undefined >my $database = DBI->connect("dbi:Pg:dbname=test"); > >$test_string = $database->quote($test_string); >$database->do(" > INSERT INTO employees(name) > VALUES($test_string) >"); ---------------------------------------------------------------------------- The following mini-program inserts an empty string: my $test_string = ""; #empty string assigned to test_string my $database = DBI->connect("dbi:Pg:dbname=test"); $test_string = $database->quote($test_string); $sql_statement = $database->do(" INSERT INTO employees(name) VALUES($test_string) "); -Mike