<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
To answer my own question - <br>
My problem occurred in a layer that was joined to a csv file. I had
"NULL" values where there was no matching join field, as one might
expect.<br>
But it turns out that the csv file had the string "null" in an
otherwise integer column for missing entries. Thus, when I thought
the field calculator was rejecting NULL values, it was actually
rejecting the "null" string.<br>
<br>
Sorry for the distraction.<br>
<br>
On 5/14/2021 4:21 PM, David Strip wrote:
<blockquote type="cite">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
I have a string field I wish to convert to int. A small subset of
the records contain NULL.<br>
I tried the following in the field calculator:<br>
<br>
<blockquote>case<br>
when ("bb_usage" IS NULL) then 0<br>
else to_int("bb_usage"")<br>
end<br>
</blockquote>
When I look at the preview, the result is correct whether or not
the field contains int or NULL. But when I try to run it, I get an
error:<br>
<br>
<img src="cid:part1.3D6258AF.2AB299C4@stripfamily.net"
alt="" class=""><br>
<br>
I also tried<br>
<br>
<blockquote>case<br>
when ("bb_usage" IS NULL) then 0<br>
when ("bb_usage" IS NULL) then to_int("bb_usage")<br>
end<br>
</blockquote>
and get the same error.<br>
<br>
I tried<br>
<blockquote>if ("bb_usage" IS NULL, 0, to_int("bb_usage"))<br>
</blockquote>
same error.<br>
<br>
I know there are workarounds, but why don't any of these work? Why
does to_int get evaluated on the NULLs?<br>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
Qgis-user mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Qgis-user@lists.osgeo.org">Qgis-user@lists.osgeo.org</a>
List info: <a class="moz-txt-link-freetext" href="https://lists.osgeo.org/mailman/listinfo/qgis-user">https://lists.osgeo.org/mailman/listinfo/qgis-user</a>
Unsubscribe: <a class="moz-txt-link-freetext" href="https://lists.osgeo.org/mailman/listinfo/qgis-user">https://lists.osgeo.org/mailman/listinfo/qgis-user</a>
</pre>
</blockquote>
<br>
<br>
</body>
</html>