¿Es posible convertir un campo de caracteres en PostgreSQL a un número entero en una consulta con nombre JPA?

@Table(name = "Table")
class Table{
 String a
 Integer b
}

here column a in table t is character varying(32)

I have tried both of these and end-up with error.

SELECT t.b from Table t where Integer.parseInt(t.a) > 0 
Error : Caused by: org.postgresql.util.PSQLException: ERROR: schema "integer" does not exist

SELECT t.b from Table t where (t.a::integer) > 0 
Error : invalid token :: at line <line number>

Muchas Gracias

preguntado el 01 de febrero de 12 a las 04:02

Your first solution is getting further, PostgreSQL is refusing it because it doesn't understand Integer.parseInt. I'm surprised your second solution is not working. Could you try SELECT t.b FROM table t WHERE CAST(t.a AS integer) > 0? -

The Query works fine. Thank You. -

1 Respuestas

The following query works fine for me.

SELECT t.b FROM table t WHERE CAST(t.a AS integer) > 0 

Respondido 02 Feb 12, 13:02

Thank you @Daniel Lyons for this answer. - Leejoy

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.