Php CodeIgniter3 order_by()如何在活动记录中最后使用空值
我将Potgresql与Codeigniter一起使用,我的查询在需要用于Php CodeIgniter3 order_by()如何在活动记录中最后使用空值,php,postgresql,codeigniter-3,Php,Postgresql,Codeigniter 3,我将Potgresql与Codeigniter一起使用,我的查询在需要用于order\u by()的列中返回空值。正如我在很多例子中看到的那样,我在SO和google上发现它们都不起作用。 当我在pgAdmin中尝试此查询时,它可以工作,并在最后一位输入空值 SELECT a.*, b.*, c.* FROM accounts a LEFT JOIN subscriptions b ON a.id = b.provider_account_id AND b.subscriber_account_
order\u by()
的列中返回空值。正如我在很多例子中看到的那样,我在SO和google上发现它们都不起作用。
当我在pgAdmin中尝试此查询时,它可以工作,并在最后一位输入空值
SELECT a.*, b.*, c.*
FROM accounts a
LEFT JOIN subscriptions b ON a.id = b.provider_account_id AND b.subscriber_account_id = 10
JOIN users c ON c.email = a.name
WHERE a.user_role = 0
ORDER BY b.following DESC NULLS LAST, b.last_updated DESC NULLS LAST;
这是Codeigniter中模型中的查询,它将空值放在第一位
$this->db->select('a.*, b.*, c.*');
$this->db->from('accounts a');
$this->db->join('subscriptions b', 'a.id = b.provider_account_id AND b.subscriber_account_id = '.$client_id, 'left');
$this->db->join('users c', 'c.email = a.name');
$this->db->where('a.user_role', 0);
$this->db->order_by('b.following', 'desc');
$this->db->order_by('b.last_updated', 'desc');
因此,我如何在
order\u by()中实现NULLS LAST
函数已解决
修改了“system/database/DB\u query\u builder.php”中的order\u by()
函数
改变
$direction = in_array($direction, array('ASC', 'DESC'), TRUE) ? ' '.$direction : '';
到
现在我可以像这样使用它了
$this->db->order_by('column', 'desc nulls first');
$this->db->order_by('column', 'desc nulls last');
$this->db->order_by('column', 'asc nulls first');
$this->db->order_by('column', 'asc nulls last');
$this->db->order_by('column', 'desc nulls first');
$this->db->order_by('column', 'desc nulls last');
$this->db->order_by('column', 'asc nulls first');
$this->db->order_by('column', 'asc nulls last');