2015-11-26 75 views
-1

此查詢返回此錯誤。如何將typecast字符串轉換爲整數 - Postgres?

操作者不存在:文本=整數LINE 2:從mas_book)作爲 OUTP其中outp.authors = 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(); 
} 

回答

3

如果outp.authors值可以被轉換成整數,然後你可以使用:

"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

2
SELECT COUNT(authors) FROM (SELECT DISTINCT regexp_split_to_table(author, E',') as authors 
      FROM mas_book) as outp WHERE outp.authors = ".'cast(.'$ids'. as character varying);