SQL命令失败:错误:运算符不存在:字符变化?

时间:2014-10-15 11:39:28

标签: postgresql

我正在尝试使用以下查询从数据库中获取值

SELECT Distinct org.name AS org, sto.ad_org_id AS wh_nearstoredetails_id, sum(sto.qtyonhand) AS qty, pro.name AS product
    FROM ad_org org, m_storage_detail sto, m_product pro
    WHERE sto.ad_org_id::text = org.ad_org_id::text
    AND (sto.m_locator_id::text IN ( select cast(m_locator.m_locator_id as text)
                        from m_locator,m_warehouse 
                        where m_warehouse.isactive = cast('Y' as varchar)
                            and m_warehouse.em_ai_warehouseparent::text not like cast('' as text)
                            and m_warehouse.m_warehouse_id::text = m_locator.m_warehouse_id::text
                            and m_locator.isdefault = cast('Y' as varchar))) 
    AND sto.m_product_id::text = pro.m_product_id::text 
    AND sto.qtyonhand >= cast(1 as numeric)
    AND sto.ad_org_id::text IN ( SELECT cast(m_warehouse.ad_org_id as text)
                    FROM m_warehouse
                    WHERE m_warehouse.em_ai_warehouseparent::text not like cast('' as text))
          GROUP BY  org.name,sto.ad_org_id,pro.name
          ORDER BY org.name, pro.name;

创建后我还创建了一个类来调用此查询并获取数据,但是当我部署我的项目时,我收到了以下错误

WARN - SQL Command failed with: ERROR: operator does not exist: character varying !
Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.

请帮助解决这个问题。

1 个答案:

答案 0 :(得分:0)

我终于找到了我犯的错误。 上述查询中的问题是我尝试进行空值类型转换

现在我改变条件检查' 不为空'比" 不喜欢' "

即使我不需要添加强制操作也没用。

无论如何,谢谢你的回复。 :)