I am trying to make a formula to choose a convenient user profile name. He chooses firstname + '' + lastname if at least one of them is not null and not empty (contains characters without spaces), otherwise he chooses shortname (with the same conditions) and, finally, if shortname is empty or empty , it selects id , is converted to a string.
@Formula("COALESCE(NULLIF(TRIM(BOTH FROM CONCAT(sp.firstname, ' ', sp.lastname)), ''), TRIM(p.shortname), to_char(p.id, 'FM9999999999999999')) " + "FROM socialprofile AS sp " + "JOIN profile AS p ON sp.id=p.id") public String getUserFriendlyName() { return super.getUserFriendlyName(); }
Result:
org.hibernate.HibernateException: Unexpected number of trim function operands : 10
but there are only 3 arguments: BOTH, FROM and the result of CONCAT. Is there any solution to this problem? DB - PostgreSQL 9.1, Hibernate version - 4.2.1. Just in case, here is the table structure:
Profile bigint id text shortname SocialProfile bigint id text firstname text lastname
They are linked as a one-to-one relationship using the id field in the SocialProfile extends Profile Java code. In the PgAdmin SQL editor, this query works fine.
source share