数据类型匹配时,postGre SQL请求类型转换吗?

时间:2018-11-24 18:13:16

标签: sql postgresql

所以我一直在这里尝试此查询:

    SELECT
     account.customer_client_code,
     account.client_account_number,
     account.first_name,
     account.last_name,
     debt_trans.trans_date,
     debt_trans.debt_id,
     debt_trans.debt_trans_id,
     debt_trans.receiver,
     debt_trans.type_name,
     debt_trans.client_id,
     debt_trans.amount

    FROM
     debt_trans 

    INNER JOIN
     account 

    ON
     account.client_id= debt_trans.client_id

      /* Both fields here are of int8 datatype */

    WHERE
     debt_trans.customer_id = 'CMC' 
     and
     account.customer_client_code like ('UBC2903','UBCO') 
     and 
     debt_trans.type_name='Credit Card'
     and
     debt_trans.operator = 'RECEIVED'

 /*All of these fields here are of varchar datatype */

但是我已经检查并仔细检查了所有数据类型,并且不应该进行任何类型转换。我收到的错误消息如下:

“错误:运算符不存在:字符变化~~记录提示:没有运算符与给定的名称和参数类型匹配。您可能需要添加显式类型强制转换。位置:492”

有什么问题的提示吗?

1 个答案:

答案 0 :(得分:2)

错误消息与此行有关:

account.customer_client_code like ('UBC2903','UBCO')

如果您尝试查看account.customer_client_code'UBC2903'还是'UBCO'之一,则应该使用IN运算符:

account.customer_client_code IN ('UBC2903','UBCO')