<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html><body style='font-family: Terminal,Monaco,monospace'>
<p>Hi Ivan,</p>
<p>I think arrays is not well supported for retrieve information from postgres, I afraid, if you go to a psql terminal and run a simple:</p>
<p>SELECT emails FROM users;</p>
<p>You realise the output is the same that you get with boss_db. Perhaps you should normalice the data, create another table for emails and another model using -has or -belongs instead.</p>
<p>Another solution is create a parser for that and in the model, use a specific function to get the data parsed. But I think this is more complex to do.</p>
<p>Regards.<br />Manuel Rubio.</p>
<p>El 2014-05-23 23:03, Ivan Carmenates García escribió:</p>
<blockquote type="cite" style="padding-left:5px; border-left:#1010ff 2px solid; margin-left:5px"><!-- html ignored --><!-- head ignored --><!-- meta ignored --><!-- meta ignored --><!-- node type 8 --><!-- node type 8 -->
<div class="WordSection1">
<p class="MsoNormal"><span>Hi every one, <!-- o ignored --></span></p>
<p class="MsoNormal"><span><!-- o ignored --> </span></p>
<p class="MsoNormal"><span>I was wondering how CB treats the database array fields,<!-- o ignored --></span></p>
<p class="MsoNormal"><span><!-- o ignored --> </span></p>
<p class="MsoNormal"><span>If I have for example a postgres script like this one:<!-- o ignored --></span></p>
<p class="MsoNormal"><span><!-- o ignored --> </span></p>
<p class="MsoNormal"><span style="font-family: Consolas;">CREATE TABLE users (<!-- o ignored --></span></p>
<p class="MsoNormal"><span style="font-family: Consolas;"> id PRIMARY KEY, <!-- o ignored --></span></p>
<p class="MsoNormal"><span style="font-family: Consolas;"> name varchar(50),<!-- o ignored --></span></p>
<p class="MsoNormal"><span style="font-family: Consolas;"> emails varchar(50) []<!-- o ignored --></span></p>
<p class="MsoNormal"><span style="font-family: Consolas;">)<!-- o ignored --></span></p>
<p class="MsoNormal"><span style="font-family: Consolas;"><!-- o ignored --> </span></p>
<p class="MsoNormal"><span>In CB a model like this:<!-- o ignored --></span></p>
<p class="MsoNormal"><span style="font-family: Consolas;"><!-- o ignored --> </span></p>
<p class="MsoNormal"><span style="font-family: Consolas;">-module(users, [Id, Name, Emails]).<!-- o ignored --></span></p>
<p class="MsoNormal"><span style="font-family: Consolas;"><!-- o ignored --> </span></p>
<p class="MsoNormal"><span>So I have inserted a record in the database and it looks as follow:<!-- o ignored --></span></p>
<p class="MsoNormal"><span style="font-family: Consolas;"><!-- o ignored --> </span></p>
<p class="MsoNormal"><span style="font-family: Consolas;">Id name emails<!-- o ignored --></span></p>
<p class="MsoNormal"><span style="font-family: Consolas;">1 Will <a href="mailto:%7bwill@gmail.com">{will@gmail.com</a>, <a href="mailto:will89@gmail.com">will89@gmail.com</a>, <a href="mailto:will2014@hotmail.com">will2014@hotmail.com</a>}<!-- o ignored --></span></p>
<p class="MsoNormal"><span style="font-family: Consolas;"><!-- o ignored --> </span></p>
<p class="MsoNormal"><span>When I do a</span><span style="font-family: Consolas;"> bossdb:find(users, []) </span><span>for the field emails I got</span><span style="font-family: Consolas;"> <<"{<a href="mailto:will@gmail.com">will@gmail.com</a>, <a href="mailto:will89@gmail.com">will89@gmail.com</a>, <a href="mailto:will2014@hotmail.com">will2014@hotmail.com</a>}">><!-- o ignored --></span></p>
<p class="MsoNormal"><span>My question is obviously, WTF??? Sorry about that!! How can I parse that!!! To a nicely, normal, pretty, good syntax of CB.<!-- o ignored --></span></p>
<p class="MsoNormal"><span style="font-family: Consolas;"><!-- o ignored --> </span></p>
<p class="MsoNormal"><span>Even I tried from the view to get the value and the value I got is</span><span style="font-family: Consolas;"> <a href="mailto:%7bwill@gmail.com">{will@gmail.com</a>, <a href="mailto:will89@gmail.com">will89@gmail.com</a>, <a href="mailto:will2014@hotmail.com">will2014@hotmail.com</a>} </span><span>in the view</span><span style="font-family: Consolas;"><!-- o ignored --></span></p>
<p class="MsoNormal"><span style="font-family: Consolas;"><!-- o ignored --> </span></p>
<p class="MsoNormal"><span style="font-family: Consolas;">test_array('GET', []) -><!-- o ignored --></span></p>
<p class="MsoNormal"><span style="font-family: Consolas;"> L = boss_db:find(test, []),<!-- o ignored --></span></p>
<p class="MsoNormal"><span style="font-family: Consolas;"> [{_, _, Emails} | R] = L,<!-- o ignored --></span></p>
<p class="MsoNormal"><span style="font-family: Consolas;"> {ok, [{emails, Emails}]}.<!-- o ignored --></span></p>
<p class="MsoNormal"><span style="font-family: Consolas;"><!-- o ignored --> </span></p>
<p class="MsoNormal"><span style="font-family: Consolas;"><!-- o ignored --> </span></p>
<p class="MsoNormal"><span>For the view <!-- o ignored --></span></p>
<p class="MsoNormal"><span style="font-family: Consolas;"><!-- o ignored --> </span></p>
<p class="MsoNormal"><span style="font-family: Consolas;"><ul><!-- o ignored --></span></p>
<p class="MsoNormal"><span style="font-family: Consolas;">{% if emails %}<!-- o ignored --></span></p>
<p class="MsoNormal"><span style="font-family: Consolas;"> {{ emails }}<!-- o ignored --></span></p>
<p class="MsoNormal"><span style="font-family: Consolas;">{% else %}<!-- o ignored --></span></p>
<p class="MsoNormal"><span style="font-family: Consolas;"> <li>Nothing to do.</li><!-- o ignored --></span></p>
<p class="MsoNormal"><span style="font-family: Consolas;">{% endif %}<!-- o ignored --></span></p>
<p class="MsoNormal"><span style="font-family: Consolas;"></ul><!-- o ignored --></span></p>
<p class="MsoNormal"><span style="font-family: Consolas;"><!-- o ignored --> </span></p>
<p class="MsoNormal"><span style="font-family: Consolas;"><!-- o ignored --> </span></p>
<p class="MsoNormal"><span>Best regards,<!-- o ignored --></span></p>
<p class="MsoNormal"><span>Ivan.<!-- o ignored --></span></p>
<p class="MsoNormal"><span style="font-family: Consolas;"><!-- o ignored --> </span></p>
<p class="MsoNormal"><span style="font-family: Consolas;"><!-- o ignored --> </span></p>
</div>
<!-- html ignored --><br />
<pre>_______________________________________________
erlang-questions mailing list
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a>
<a href="http://erlang.org/mailman/listinfo/erlang-questions">http://erlang.org/mailman/listinfo/erlang-questions</a>
</pre>
</blockquote>
</body></html>