[erlang-questions] How to insert null value into map

Richard A. O'Keefe <>
Wed Sep 13 23:52:34 CEST 2017



On 14/09/17 12:50 AM, Palanikumar Gopalakrishnan wrote:
> Hi Hugo,
>
>                 Null value showed in sql
>
>  +---------------------+
> | NULL                |
> | NULL                |
> +---------------------+
>
> When we applied it with map like below, It returns the following error
> *()27> maps:get("A", NULL, Some).
> * 1: variable 'NULL' is unbound
> ()28>

That is because NULL is indeed an Erlang *variable* name.
'NULL', null, "NULL", <<"NULL">>, [], {} and a whole lot
of other alternatives are not variables.

Now maps:get(Key, Map, Default) wants a Map as its second
argument.  Presumably your data base interface returns a
row as a map, so you should be looking at something like
#{"A" => null, "B" => null}
for a row with columns A and B, both having null values.
But you need to check the documentation for your data base
interface.

PS:  SQL keywords are not case sensitive: NULL = null = Null = nUlL.
My own SQL style puts keywords in lower case and other identifiers
in Mixed_Case_Well_Separated (just as in the Ada Quality and Style
Guidelines for Ada).  Point is, there isn't the slightest reason in
any programming language other than SQL why SQL's "null" should be
represented as NULL.  Also, quoting the MySQL manual,
"Column, index, stored routine, and event names are not
  case sensitive on any platform, nor are column aliases."
So are you really sure that "A" should be "A" and not "a"?


More information about the erlang-questions mailing list