1

I know that money type is not good to use in Postgres, but I can't change it and I need to get this value in Java.

I have already tried to use Double, BigDecimal, String, etc. But all of then I get an error like that

Schema-validation: wrong column type encountered in column [xpto] in table [xpto]; found [money (Types#DOUBLE)], but expecting [numeric(19, 2) (Types#NUMERIC)]

I don't know what type I have to declare in my variable. Someone can help me?

Igor Ramos
  • 251
  • 1
  • 2
  • 8
  • "*but I can't change it*" yes of course you can. Just run an ALTER TABLE. –  Apr 11 '20 at 15:33
  • No, I can't. Because this database is used for others teams in my company and have no permission to alter it. – Igor Ramos Apr 11 '20 at 15:37
  • When I try retrive the value as a string, I get this error "found [money (Types#DOUBLE)], but expecting [varchar(255) (Types#VARCHAR)]" – Igor Ramos Apr 11 '20 at 15:45
  • 1
    You can cast it to the correct data type in your SELECT statement: `select xpto::numeric, ...` - but you will probably need to use a native query for that. Or create a view that fixes the wrong data type and use that in your application (but I don't know if your obfuscation layer can deal with a view rather than a table) –  Apr 11 '20 at 15:49
  • The alternative is to use `getString() - but you will probably need to declare your variable as a String to workaround the limitations of the obfuscation layer. –  Apr 11 '20 at 15:55
  • Can I cast of this way using JPA? – Igor Ramos Apr 11 '20 at 16:06
  • No idea, I don't use obfuscation layers. –  Apr 11 '20 at 16:19

0 Answers0