Re: What is the difference between NULL and "undef" - Mailing list pgsql-sql

From Michael A. Mayo
Subject Re: What is the difference between NULL and "undef"
Date
Msg-id 00ff01bfc10d$63b057a0$1138b798@362197428
Whole thread Raw
In response to AW: What is the difference between NULL and "undef"  ("Rudolph, Michael" <Michael.Rudolph@telekom.de>)
List pgsql-sql
----- Original Message ----- >
> 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.

Oops...I missed this last part.  If you don't want to have to do the quoting
yourself, use the quote() method and make any empty strings undef instead
NULL.

$database = connect();
$name = $database->quote($var);
$database->do("insert into employees(name) values $var");

if $var is undef, it inserts null, if not it properly quotes the string,
including escaping any nasty characters it might include like the
apostrophe.

In the future, you might want to post questions like this to the dbi-users
list; you are more likely to get help there.  Also, you may want to take a
look at the book "Programming the Perl DBI," or, if you are more harcore,
try the command "perldoc DBI."   This stuff is pretty well documented in
both those resources.
                -Mike




pgsql-sql by date:

Previous
From: Kate Collins
Date:
Subject: Re: SQL command speed
Next
From: Tom Lane
Date:
Subject: Re: SQL command speed