Diego:<div><br></div><div>Didn&#39;t wrote a prepaid system already? how did you compare the prefix in that system then?<br><br><div class="gmail_quote">On Wed, Oct 14, 2009 at 10:07 AM, TTNC - Adnan Barakat <span dir="ltr">&lt;<a href="mailto:technical@ttnc.co.uk">technical@ttnc.co.uk</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="im">Diego Viola wrote:<br>
&gt; I&#39;m using MySQL now but I will try PostgreSQL with the prefix module, is<br>
&gt; there a way to do that without the prefix module and with regular SQL?<br>
&gt;<br>
&gt; Any examples?<br>
</div>SELECT * FROM rates WHERE prefix = SUBSTRING(&#39;$NUMBER$&#39;, 1,<br>
LENGTH(prefix)) LIMIT 1<br>
<br>
Adnan<br>
<div class="im"><br>
&gt; Diego<br>
&gt;<br>
&gt; On Tue, Oct 13, 2009 at 10:45 PM, Even André Fiskvik &lt;<a href="mailto:grevenx@me.com">grevenx@me.com</a><br>
</div><div><div></div><div class="h5">&gt; &lt;mailto:<a href="mailto:grevenx@me.com">grevenx@me.com</a>&gt;&gt; wrote:<br>
&gt;<br>
&gt;     What database are you using?<br>
&gt;     You could do this with regular SQL, but it would by a costly operation,<br>
&gt;     for PostgreSQL we&#39;re using the prefix module:<br>
&gt;     <a href="http://pgfoundry.org/projects/prefix/" target="_blank">http://pgfoundry.org/projects/prefix/</a><br>
&gt;<br>
&gt;     You can then match the closest prefix by using something like<br>
&gt;     &quot;WHERE myprefix_col @&gt; caller_destination_number ORDER BY LENGTH<br>
&gt;     (myprefix_col::text) LIMIT 1;&quot;<br>
&gt;<br>
&gt;<br>
&gt;     Best regards,<br>
&gt;     Even André<br>
&gt;<br>
&gt;<br>
&gt;     On 13. okt. 2009, at 23.53, Diego Viola wrote:<br>
&gt;<br>
&gt;     &gt; Hello,<br>
&gt;     &gt;<br>
&gt;     &gt; I&#39;m trying to write a post-paid billing script, I have the CDR on my<br>
&gt;     &gt; database and also a &quot;rates&quot; table, the CDR contains fields like<br>
&gt;     &gt; caller_destination_number, variable_duration, etc. and the rates<br>
&gt;     &gt; table contains: destination, prefix, rate (cost).<br>
&gt;     &gt;<br>
&gt;     &gt; The problem is that I can&#39;t just strip the destination number to<br>
&gt;     &gt; take the prefix from it because I have to deal with destination<br>
&gt;     &gt; numbers from different countries and they all have different prefix<br>
&gt;     &gt; lengths... so I need to find another way to take the prefix from the<br>
&gt;     &gt; destination number.<br>
&gt;     &gt;<br>
&gt;     &gt; Any ideas how to do this?<br>
&gt;     &gt;<br>
&gt;     &gt; Thanks,<br>
&gt;     &gt;<br>
&gt;     &gt; Diego<br>
&gt;     &gt;<br>
&gt;     &gt; _______________________________________________<br>
&gt;     &gt; FreeSWITCH-users mailing list<br>
&gt;     &gt; <a href="mailto:FreeSWITCH-users@lists.freeswitch.org">FreeSWITCH-users@lists.freeswitch.org</a><br>
</div></div>&gt;     &lt;mailto:<a href="mailto:FreeSWITCH-users@lists.freeswitch.org">FreeSWITCH-users@lists.freeswitch.org</a>&gt;<br>
<div class="im">&gt;     &gt; <a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br>
&gt;     &gt; UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-</a><br>
&gt;     &gt; users<br>
&gt;     &gt; <a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
&gt;<br>
&gt;<br>
&gt;     _______________________________________________<br>
&gt;     FreeSWITCH-users mailing list<br>
&gt;     <a href="mailto:FreeSWITCH-users@lists.freeswitch.org">FreeSWITCH-users@lists.freeswitch.org</a><br>
</div>&gt;     &lt;mailto:<a href="mailto:FreeSWITCH-users@lists.freeswitch.org">FreeSWITCH-users@lists.freeswitch.org</a>&gt;<br>
<div><div></div><div class="h5">&gt;     <a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br>
&gt;     UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br>
&gt;     <a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; ------------------------------------------------------------------------<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; FreeSWITCH-users mailing list<br>
&gt; <a href="mailto:FreeSWITCH-users@lists.freeswitch.org">FreeSWITCH-users@lists.freeswitch.org</a><br>
&gt; <a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br>
&gt; UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br>
&gt; <a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
<br>
<br>
_______________________________________________<br>
FreeSWITCH-users mailing list<br>
<a href="mailto:FreeSWITCH-users@lists.freeswitch.org">FreeSWITCH-users@lists.freeswitch.org</a><br>
<a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br>
UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br>
<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Henry Huang<br>UniC Solution - Communication Unified<br>VoIP &amp; Open Source software Consultant<br>
</div>