[Melbourne-pm] Strange things about '0'

Mathew Robertson mathew.robertson at netratings.com.au
Mon Oct 27 21:26:15 PDT 2008

>>> Now, if $query_var is a 0 then the ? in the above sql there are no 
>>> results returned from the query, but the Perl code doesn't break. 
>>> The Ingres db system must get passed a false value.
>>> If I change $query_var to be '0' to try and get the right string 
>>> into the query in the $report->execute statement it doesn't work. 
>>> Again the Perl code doesn't break, but I still don't get any results.
>>> As the I see the Camel book mentions, Perl equates 0 and '0' both to 
>>> be false. I think this is why there ar no results of both 0 and '0'.
>> Its not Perl's fault -> it (aka DBI) will be passing the literal 
>> value to the database - the database should automatically quote 
>> numeric values.  What you can do is try a simple SQL statement 
>> directly to your db, eg:
>> SELECT * FROM some_table WHERE some_column = 0;
>> If this doesn't fail with a bad-statement error, then your db install 
>> (like most databases), automatically quotes numeric values.
> Yep, I knew it wouldn't be Perl's fault. But I wasn't sure if it was 
> my own or not. :)
> The above SQL does fail with an error. It is on an old Ingres 2.6 
> installation. The later versions might handle numeric character to 
> integer conversion better.
> * select * from valid_disp where disp = 0 \g
> Executing . . .
> E_US1130 illegal character to integer conversion or non-numeric character
>    in money field.
well what do you know... :)

it might be worthwhile sending an email to the DBD::Ingres driver 
developer, suggesting he adds a tech-note to the perldoc, about this 
quirk.  It might even be possible that the driver could be made to 
automatically handle the conversion for you... eg: detecting when a 
literal number is used, then converting it to a string.


More information about the Melbourne-pm mailing list