How to insert null value into map

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

How to insert null value into map

Palanikumar Gopalakrishnan
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.


Thanks in Advance

--

Warm Regards,

Palanikumar Gopalakrishnan ✌
Developer



_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: How to insert null value into map

Hugo Mills-2
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
hugo@... carfax.org.uk | should execute their trainer!
http://carfax.org.uk/  |
PGP: E2AB1DE4          |                      Ming the Merciless, Flash Gordon

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions

signature.asc (853 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: How to insert null value into map

Palanikumar Gopalakrishnan
Hi Hugo,

                Null value showed in sql

 +---------------------+
| NULL                |
| NULL                |
+---------------------+

When we applied it with map like below, It returns the following error
(cowboy_ws_server@Erlang)27> maps:get("A", NULL, Some).
* 1: variable 'NULL' is unbound
(cowboy_ws_server@Erlang)28>







On 13 September 2017 at 17:35, Hugo Mills <[hidden email]> 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
hugo@... carfax.org.uk | should execute their trainer!
http://carfax.org.uk/  |
PGP: E2AB1DE4          |                      Ming the Merciless, Flash Gordon



--

Warm Regards,

Palanikumar Gopalakrishnan ✌
Developer



_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: How to insert null value into map

Hugo Mills-2
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
>
> *(cowboy_ws_server@Erlang)27> maps:get("A", NULL, Some).* 1: variable
> 'NULL' is unbound(cowboy_ws_server@Erlang)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
call.

   Hugo.

> On 13 September 2017 at 17:35, Hugo Mills <[hidden email]> 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
hugo@... carfax.org.uk | should execute their trainer!
http://carfax.org.uk/  |
PGP: E2AB1DE4          |                      Ming the Merciless, Flash Gordon

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions

signature.asc (853 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: How to insert null value into map

Brujo Benavides-3
In reply to this post by Palanikumar Gopalakrishnan
Palanikumar:

On one hand, you should show us what’s in your Some variable.
On the other hand, you don’t seem to be using <a href="maps:get/3" class="">maps:get/3 as it’s intended to be used (check the docs).
Even more so, you should know that in Erlang variables start with an uppercase letter, that’s why in your example NULL is a variable name (not a value). See how Erlang VM tells you that the variable ‘NULL’ is unbound.

Hope this helps,
Cheers!

On Sep 13, 2017, at 09:50, Palanikumar Gopalakrishnan <[hidden email]> wrote:

Hi Hugo,

                Null value showed in sql

 +---------------------+
| NULL                |
| NULL                |
+---------------------+

When we applied it with map like below, It returns the following error
(cowboy_ws_server@Erlang)27> maps:get("A", NULL, Some).
* 1: variable 'NULL' is unbound
(cowboy_ws_server@Erlang)28>







On 13 September 2017 at 17:35, Hugo Mills <[hidden email]> 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
hugo@... carfax.org.uk | should execute their trainer!
http://carfax.org.uk/  |
PGP: E2AB1DE4          |                      Ming the Merciless, Flash Gordon



--

Warm Regards,

Palanikumar Gopalakrishnan ✌
Developer


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: How to insert null value into map

Richard A. O'Keefe-2
In reply to this post by Palanikumar Gopalakrishnan


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
> *(cowboy_ws_server@Erlang)27> maps:get("A", NULL, Some).
> * 1: variable 'NULL' is unbound
> (cowboy_ws_server@Erlang)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"?
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions