Although ThisSuitlsBlackNot is almost correct, there are some important omissions from his answer. As the author of most of the StrictlyTyped and DiscardString attributes, I can tell you that the DiscardString attribute is actually much more important in this case.
DBI will try to transfer your data to the specified TYPE, and if this fails, your data will be left alone and no error will be generated. If the failure is completed and StrictlyTyped is specified, an error is generated.
The DiscardString attribute discards the line portion of your data (pv) is discarded. This is especially important when using JSON :: XS and possibly other JSON modules, since JSON :: XS specifically looks at pv.
So you should do at least:
$sth->bind_col(1, undef, {TYPE => SQL_INTEGER, DiscardString => 1});
NOTE. Several DBDs actually pay attention to the type of binding in bind_col. DBD :: ODBC does because I support it. DBD :: Oracle does not pay attention to the TYPE usually, except when used with StrictlyTyped and / or DiscardString (because I added this functionality exactly for the same problem as yours).
If the driver supports these attributes or not, this can really be confirmed (if not specified in the documentation) by looking for the code to use sql_type_cast and their equivalents xs sql_type_cast_svpv, etc. I do not believe that DBD :: Pg supports StrictlyTyped or DiscardString; in fact, I believe that at this time only DBD :: ODBC and DBD :: Oracle do (as they are added).
You can also find this interesting.
bohica
source share