I use the PostgreSQL table agents. It has a column zip_codes character(5)[] that stores the zip codes of the areas the agents are responsible for.
It stores agent1 with the zip codes {11111,22222} and agent2 with the zip code {33333}.
I want to look for all agents that are responsible for a special area.
Without Hibernate it is easy: SELECT * FROM agents WHERE '11111' = ANY (zip_codes) returns agent1.
But how do I make it with HQL? It does not know any. But if I use in instead, I will get wrong results: if I write select agents from Agents as agents where '{11111}' in (agents.zip_codes), agent1 will not be found. If I use '{33333}' instead, agent2 will be found.
Of course I can search with something like (in sql) WHERE zip_codes[1] = '11111' OR zip_codes[2] = '11111' (arrays in PostgreSQL start with index 1), but this is not handy for many entries in zip_codes.
textfield type for them? In that case the problem is that you're looking for {11111} with closing bracket, but your field also contains 22222. You should look for 11111 in that case, without bracketsselect agents from Agents as agents where '11111' in (agents.zip_codes)? Then PostgreSQL throws an error:malformed array literal: "11111" ... Array value must start with "{" or dimension information.