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

Hugo Mills <>
Wed Sep 13 15:01:35 CEST 2017

On Wed, Sep 13, 2017 at 06:20:38PM +0530, Palanikumar Gopalakrishnan wrote:
> Hi Hugo,
>                 Null value showed in sql
>  +---------------------+
> | NULL                |
> | NULL                |
> +---------------------+

   This is the printed human-readable representation of the output
from some tool which isn't itself erlang or the SQL library you're
using. So yes, you have null values in the result, but it doesn't tell
you how they are represented in erlang code.

> 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's because NULL is a variable -- in fact, the error message
tells you *exactly* that.

   In erlang code, variables start with a capital letter and are
unquoted, so this is clearly not going to work, and the compiler is
telling you this.

   Also, you have the order of the parameters for maps:get/3
wrong. Check the documentation for what order they should go in.

   Finally, what value should you be using to find the NULL? Well, it
depends on how it's represented by the library you're using. It should
be in the documentation for the library. If it isn't, then you could
just look at the actual data in your map (print the map with
io:format("~p~n", [Some])). You should then be able to see how a null
is represented, and you can use that representation in your maps:get


> On 13 September 2017 at 17:35, Hugo Mills <> wrote:
> > On Wed, Sep 13, 2017 at 05:01:37PM +0530, Palanikumar Gopalakrishnan wrote:
> > > Hi Guys,
> > >                 I want to get data from mysql and append them into map.
> > But
> > > some row had null values. Hence i cant able to convert the null value
> > into
> > > map. Its there any way to convert null value into map.
> >
> >    Why can't you put nulls into a map? This works, for example:
> >
> > 2> #{null => null}.
> > #{null => null}
> >
> > so we can clearly put some null atom in both key and value positions
> > in a map.
> >
> >    If you could show an example row without a null, and what that
> > turns into when you put it in a map, and then show how this fails when
> > you do have a null, then it might be easier to answer your question.
> >
> >    Hugo.
> >

Hugo Mills             | Klytus! Are your men on the right pills? Maybe you
 carfax.org.uk | should execute their trainer!
http://carfax.org.uk/  |
PGP: E2AB1DE4          |                      Ming the Merciless, Flash Gordon
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20170913/2a660674/attachment.bin>

More information about the erlang-questions mailing list