使用PostgreSQL CONCAT函数时出现500内部服务器错误

时间:2018-01-22 09:16:32

标签: ajax postgresql codeigniter concatenation

基于此question最终可以比以前更快地在phppgAdmin中显示查询结果。只有在LIMIT 1函数之后添加PostgreSQL CONCAT才能使用不同的约5s(从7s到2s)。

这是我的简短的SQL:

$sql = "select tb1.*, 
(select name_code from master_code tb2 where tb2.code like CONCAT('%', tb1.code, '%') LIMIT 1) as master_code_name
from city tb1 where tb1.location_id like 'blablabla%'";

我使用此脚本根据city显示location_id。一列city包含master_code的代码。 实际上,我只是想尝试显示该列的名称。但是,当我尝试使用ModelController加载时,在500 Internal Server Error中显示console

这是Model中的代码:

  public function select_by_location(){

    $sql = "select tb1.*, (select name_code from master_code tb2 where tb2.code like CONCAT('%', tb1.code, '%') LIMIT 1) as master_code_name from city tb1 where tb1.location_id like 'blablabla%'";

        $data = $this->db->query($sql);

        return $data->result_array();
    }

这是控制器:

 public function show() {
     $data['dataCity'] = $this->M_city->select_by_location();
     $this->load->view('city/list_data', $data);
 }

的Ajax:

  function showCityAjax() {
    $.get('<?php echo base_url('City_controller/show'); ?>', function(data) {
        $('#data-city').html(data);
        refresh();
    });
  }

显示结果:

<div id="data-city"></div>

如何解决这个问题?或者是否有其他方法可以更有效地完成它。感谢。

0 个答案:

没有答案