I am using feed module to import form excel file, one of my field is a incremental number 1,2,3,4,5 ,..... ' , I get it as 'GUID' in feed importer. I want sort the result in views, I see the views get GUID as a string and sort it by string.anybody have idea how can I sort them as number ? I want views sort GUID as integer not string

I test this but it return me sql error,

The sql query of first(top) test :

SELECT node.title AS node_title, node.nid AS nid, feeds_item.guid AS feeds_item_guid, 'node' AS field_data_field_model_node_entity_type, 'node' AS field_data_field_price_node_entity_type
{node} node
LEFT JOIN {feeds_item} feeds_item ON node.nid = feeds_item.entity_id AND feeds_item.entity_type = 'node'
WHERE (( (node.status = '1') AND (node.type IN  ('products')) ))

function mymodule_views_query_alter(&$view, &$query) {
if ($view->name == 'my_views') {
$query->orderby[0]['field']='CAST('.$query->orderby[0]["field"].' AS INTEGER)';    

or I try

$query->fields['feeds_item_guid']['field']='CAST('.$query->fields['feeds_item_guid']['field'].' AS INTEGER)';

error of second try: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'feeds_item.CASTguidASINTEGER' in 'field list'

  • Could you post the SQL error as well please? It's likely that you'll need to add an expression to the query rather than a field (which will be sanitised and aliased, probably causing the error you're getting). You could also use hook_query_alter() long with one of the methods in this question to see exactly what SQL string is being built - that'll probably give you a bit more insight into the problem – Clive Dec 30 '13 at 22:02
  • @Clive I want tell it sort it as number not string. do you think this is true way or you have better idea? – Yusef Mohamadi Dec 30 '13 at 22:06
  • @Clive the question updated. look at it again – Yusef Mohamadi Dec 30 '13 at 22:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.