<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Tips about nulls in SQL in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/tips-about-nulls-in-sql/m-p/1192087#M57217</link>
    <description>&lt;P&gt;There are some good comments in this sister post:&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.oracle.com/tech/developers/discussion/comment/16841159/#Comment_16841159" target="_self"&gt;Oracle Groundbreakers Community -&amp;nbsp;Tips about nulls in SQL&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 14 Jul 2022 00:08:48 GMT</pubDate>
    <dc:creator>Bud</dc:creator>
    <dc:date>2022-07-14T00:08:48Z</dc:date>
    <item>
      <title>Tips about nulls in SQL</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/tips-about-nulls-in-sql/m-p/1188966#M56882</link>
      <description>&lt;P&gt;What are some tips about nulls in SQL you can share? As GIS professionals, not SQL developers, it's easy to make mistakes when dealing with nulls in SQL.&lt;/P&gt;&lt;P&gt;For example:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;We can't do math on nulls:&amp;nbsp;1 + NULL = NULL.&lt;OL class="lia-list-style-type-lower-alpha"&gt;&lt;LI&gt;Sometimes, people assume nulls will be automatically treated as zero. But that's not the case. We would need to explicitly convert nulls to something else (like zero) using COALESCE(), NVL(), etc..&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;LI&gt;NULL doesn't equal NULL. More specifically, null is neither equal to, nor is it not equal, to null.&lt;OL class="lia-list-style-type-lower-alpha"&gt;&lt;LI&gt;WHERE NULL = NULL won't return any results. Neither will WHERE NULL &amp;lt;&amp;gt; NULL.&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;Further, be careful for cases like WHERE A &amp;lt;&amp;gt; B. Let's say A is 1 and B is null. That row won't get selected, because null is neither equal to, nor is it not equal, &lt;STRONG&gt;to anything.&lt;/STRONG&gt;&lt;/LI&gt;&lt;LI&gt;Joining on null values won't work either.&lt;/LI&gt;&lt;LI&gt;Related:&amp;nbsp;&lt;UL&gt;&lt;LI&gt;&lt;A href="https://modern-sql.com/caniuse/is-not-distinct-from" target="_self"&gt;IS NOT DISTINCT FROM&lt;/A&gt;&lt;/LI&gt;&lt;LI&gt;SQLite:&amp;nbsp;&lt;A href="https://stackoverflow.com/questions/72838001/null-safe-equals-comparison/72838002#72838002" target="_self"&gt;Null-safe equals comparison&lt;/A&gt;&amp;nbsp;using IS instead of =.&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;LI&gt;Aggregate functions such as AVG() will ignore nulls.&amp;nbsp;&lt;A href="https://stackoverflow.com/questions/22220449/sql-avg-with-null-values" target="_self"&gt;AVG(4,4,4,4,4,NULL)&lt;/A&gt;&amp;nbsp;will evaluate to 4 (not&amp;nbsp;3.33).&lt;/LI&gt;&lt;LI&gt;But be careful when doing math on the result of aggregate functions. Example: SUM(A) + SUM(B). Remember, we can't do math on nulls. So if the result of either of those aggregate functions is null, then the entire expression will evaluate to null.&lt;/LI&gt;&lt;LI&gt;Different databases concatenate nulls differently. &lt;A href="https://webcache.googleusercontent.com/search?q=cache:9ivrLKYhQpgJ:https://www.modern-sql.com/sql/where-clause/null+&amp;amp;cd=1&amp;amp;hl=en&amp;amp;ct=clnk&amp;amp;gl=ca#:~:text=except%20in%20the%20Oracle" target="_self"&gt;For example, in Oracle,&lt;/A&gt; nulls will be ignored in this concatenation: 'FOO ' || NULL || 'BAR' …will evaluate to… FOO BAR. But in other databases, that would result in NULL.&lt;/LI&gt;&lt;LI&gt;Different databases treat empty strings differently. For example, in Oracle, &lt;A href="https://dbfiddle.uk/?rdbms=oracle_18&amp;amp;fiddle=5ab8502490f65666ee6395eac077de56" target="_self"&gt;SELECT '' FROM MY_TABLE&lt;/A&gt; will result in null. That's important to know for things like #1 above. We wouldn't want to replace NULL with '', since '' would simply result in null. With that said, putting a space ' ' between the single quotes would work; that won't get automatically converted to null.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;BR /&gt;Are there any other gotchas or tips about nulls you can share? Or any improvements or corrections to the points above?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Related:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;A href="https://modern-sql.com/concept/null" target="_self"&gt;NULL in SQL: Indicating the Absence of Data&lt;/A&gt;&lt;/LI&gt;&lt;LI&gt;&lt;A href="https://docs.oracle.com/en/database/oracle/oracle-database/18/sqlrf/Nulls.html#GUID-B0BA4751-9D88-426A-84AD-BCDBD5584071" target="_self"&gt;Oracle Documentation - NULLS&lt;/A&gt;&lt;/LI&gt;&lt;LI&gt;&lt;A href="https://modern-sql.com/concept/three-valued-logic" target="_self"&gt;The Three-Valued Logic of SQL&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;</description>
      <pubDate>Mon, 11 Jul 2022 18:17:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/tips-about-nulls-in-sql/m-p/1188966#M56882</guid>
      <dc:creator>Bud</dc:creator>
      <dc:date>2022-07-11T18:17:42Z</dc:date>
    </item>
    <item>
      <title>Re: Tips about nulls in SQL</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/tips-about-nulls-in-sql/m-p/1188967#M56883</link>
      <description>&lt;P&gt;Don't use them&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/t5/python-blog/the-solution-to-lt-null-gt-in-tables/ba-p/902845" target="_blank"&gt;The solution to &amp;lt;null&amp;gt; in tables - Esri Community&lt;/A&gt;&lt;/P&gt;&lt;P&gt;query out the defaults before using the remainder&lt;/P&gt;&lt;P&gt;Somewhat tongue-in-cheek, but setting a value to replace a null, which as you point out, enables you to get at valid data.&lt;/P&gt;&lt;P&gt;The downside is that it requires an extra step to get there.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 02 Jul 2022 08:51:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/tips-about-nulls-in-sql/m-p/1188967#M56883</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2022-07-02T08:51:14Z</dc:date>
    </item>
    <item>
      <title>Re: Tips about nulls in SQL</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/tips-about-nulls-in-sql/m-p/1192087#M57217</link>
      <description>&lt;P&gt;There are some good comments in this sister post:&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.oracle.com/tech/developers/discussion/comment/16841159/#Comment_16841159" target="_self"&gt;Oracle Groundbreakers Community -&amp;nbsp;Tips about nulls in SQL&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jul 2022 00:08:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/tips-about-nulls-in-sql/m-p/1192087#M57217</guid>
      <dc:creator>Bud</dc:creator>
      <dc:date>2022-07-14T00:08:48Z</dc:date>
    </item>
  </channel>
</rss>

