如何将字符串转换为整数 - Postgres?

时间:2015-11-26 05:14:07

标签: sql postgresql codeigniter

此查询,返回此错误。

  

运算符不存在:text = integer LINE 2:from mas_book)as   outp where out.Outhors = 2 ^提示:没有运算符匹配给定的名称   和参数类型。您可能需要添加显式类型转换

public function authors($ids)
{
  $query = "select count(authors) from (select distinct regexp_split_to_table(author, E',') as authors
        from mas_book ) as outp where outp.authors = ".$ids;
        $result =   $this->db->query($query);
     return $result->result();
}

2 个答案:

答案 0 :(得分:3)

如果outp.authors值可以转换为Integer,那么您可以使用:

"select count(authors) from (select distinct regexp_split_to_table(author, E',') as authors
        from mas_book ) as outp where to_number(outp.authors,'9999999') = ".$ids; 

如果它不起作用,那么See this Link

答案 1 :(得分:2)

 (function() {
    'use strict';


    angular.module('eventMod').filter('eventPrivacyFilter', eventPrivacyFilter);


    function eventPrivacyFilter(EventPrivacyRegistry) {
        return function(privacyId) {
            if (!privacyId) {return null;}
            return EventPrivacyRegistry.getById(privacyId).name;
        };
    }
})();