<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Jonathan Rockway wrote:
<blockquote cite="mid:47254BE8.5010903@jrock.us" type="cite">
  <pre wrap="">Randy Moore wrote:
  </pre>
  <blockquote type="cite">
    <pre wrap="">Hi,

I'm very new with DBIx-Class, but I don't think I'm doing anything
wrong &lt;grin&gt;.  It looks like the 'as' attribute to a search is not
working.
I'm running inside of Catalyst BTW, and I've created a trivial example
that I think should work.

       my $rs = $c-&gt;model('PjAppDB::Categories')-&gt;search(undef, {
               select =&gt; [
                 'name',
                 { length =&gt; 'name' }
               ],
               as =&gt; ['name', 'namelength'],
       });
       my $result = $rs-&gt;first();

My Categories model class *does* have a column named 'name'.

This code is producing:   SELECT name, LENGTH( name ) FROM categories me
But I think it should produce:  SELECT name name, LENGTH( name )
namelength FROM categories me

The SQL query that it does produce works perfectly, I just don't see
how I can access the result for the LENGTH.
I was expecting to use $result-&gt;get_column('namelength')

Am I missing something blindingly obvious? 
    </pre>
  </blockquote>
  <pre wrap=""><!---->
I'm not really sure what you're trying to do... but keep in mind that
"as" has nothing to do with the SQL produced.  The "as" name is what you
pass to "get_column" when you want that data.  An example:

   my $result = $foo_rs-&gt;search({}, {
       select =&gt; [{ COUNT =&gt; 1 }],
       as       =&gt; 'foos',
   });

This will produce something equivalent to "SELECT *, COUNT(1) FROM
....".  The information that the database returns as COUNT(1) will be
available as "$result-&gt;get_column('foos')".

Regards,
Jonathan Rockway
  </pre>
</blockquote>
Ok, I now see that the 'AS' info does not actually get built into the
SQL query.&nbsp; So, what I'm trying to do will not work.<br>
<br>
I'm really trying to use the result of a SQL function in the 'order_by'
clause.<br>
<br>
The SQL I'm trying to produce is something like:<br>
<br>
SELECT name, LENGTH( name ) AS namelength ORDER BY namelength<br>
<br>
This is one small piece of a search query I'm dynamically building up
based on results from an html form.&nbsp; I've got it all working but the
ordering.&nbsp; And, I'm trying to avoid re-ordering the resulting data in
code because I'm using the page and rows attributes to page through the
results.<br>
<br>
I had thought the 'AS' attribute was the key, so I"m off to find
another approach.<br>
<br>
Thanks.<br>
<br>
<blockquote cite="mid:47254BE8.5010903@jrock.us" type="cite">
  <pre wrap="">
  </pre>
  <pre wrap="">
<hr size="4" width="90%">
_______________________________________________
List: <a class="moz-txt-link-freetext" href="http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class">http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class</a>
IRC: irc.perl.org#dbix-class
SVN: <a class="moz-txt-link-freetext" href="http://dev.catalyst.perl.org/repos/bast/DBIx-Class/">http://dev.catalyst.perl.org/repos/bast/DBIx-Class/</a>
Searchable Archive: <a class="moz-txt-link-freetext" href="http://www.grokbase.com/group/dbix-class@lists.rawmode.org">http://www.grokbase.com/group/dbix-class@lists.rawmode.org</a></pre>
</blockquote>
<br>
<br>
<pre class="moz-signature" cols="72">-- 
Randy Moore
Axion Information Technologies, Inc.

phone: 301-587-3300 x 511
fax:   301-585-7450

<a class="moz-txt-link-freetext" href="http://www.axion-it.com">http://www.axion-it.com</a>
</pre>
</body>
</html>