How do I cast a string to integer and have 0 in case of error in the cast with PostgreSQL?

前端 未结 13 950
误落风尘
误落风尘 2020-12-02 06:27

In PostgreSQL I have a table with a varchar column. The data is supposed to be integers and I need it in integer type in a query. Some values are empty strings. The followin

13条回答
  •  误落风尘
    2020-12-02 06:59

    I also have the same need but that works with JPA 2.0 and Hibernate 5.0.2:

    SELECT p FROM MatchProfile p WHERE CONCAT(p.id, '') = :keyword
    

    Works wonders. I think it works with LIKE too.

提交回复
热议问题