Sorting With 'desc Nulls Last'

PostgreSQL knows the sorting option


SORT BY row DESC NULLS LAST

That means, that rows with NULL get sorted behind 1 or 0 for example. The default instead is, that all NULLs get sorted in front of 1 or 0 which is annoying in my case.

Now, CSqlDataProvider doesn’t seem to know that sorting and I am wondering how can I modify the code of yii to add the NULLS LAST thing behind every SORT BY row DESC (maybe even permanently).

Can anyone help me with that?

try to provide sorting definition like this:




$dataProvider=new CSqlDataProvider($sql, array(

    ...

    'sort'=>array(

        'attributes'=>array(

             'id', 'username', 'email',

             'myattr'=>array(

                'asc'=>'myattr ASC NULLS LAST',

                'desc'=>'myattr DESC NULLS LAST'

             )

        ),

    ),

    ...

));



you can read more about this here: http://www.yiiframework.com/doc/api/1.1/CSort#attributes-detail

That did the trick and it also works together with the default sorting:




'sort'=>array(

    'attributes'=>array(

         'id', 'username', 'email', 'myattribut'=>array(

            'asc'=>'myattribut ASC NULLS LAST',

            'desc'=>'myattribut DESC NULLS LAST'

         )

    ),

    'defaultOrder'=>array(

        'myattribut'=>'SORT_DESC',

    ),

),

Thanks a lot!