3

My PostgreSQL contains an enum like

create type my_type as enum('VAL1', 'VAL2')

in Spring boot app, it is represented by MyType.class enum

I'm trying to run a simple query using DatabasClient

client.exectute("select * from table where type = :type")...

As an error I'm getting:

ceptionFactory$PostgresqlBadGrammarException: operator does not exist: type = character varying

Casting type to my_type doesn't work (both with CAST and ::)

I've already registered a specific codec for MyType.class which works - querying all without conditions works with the relevant @ReadingConverter

royB
  • 12,779
  • 15
  • 58
  • 80

1 Answers1

1

Neither Spring Data R2DBC nor R2DBC Postgres can map your enum type to Postgres enum types.

You can still use Postgres enum types represented as strings if you properly cast the bind value/column value on retrieval in your SQL statement.

Example:

client.exectute("select type::text from table where type = :type::my_type")
royB
  • 12,779
  • 15
  • 58
  • 80
mp911de
  • 17,546
  • 2
  • 55
  • 95
  • I'm not sure I understand your answer - r2dbc can (and is) map my enums using a custom codec. casting is not working as well. If u have an answer, It will be great to add a code example. – royB May 28 '20 at 14:10
  • It will be great if u can add a Casting example. I tried all the casting methods I know of and still got character varying error – royB May 28 '20 at 14:17
  • thanks, happy that my question (maybe?) resulted in a PR https://github.com/r2dbc/r2dbc-postgresql/pull/284/files – royB May 29 '20 at 20:31