My PostgreSQL包含一个枚举,例如
create type my_type as enum('VAL1', 'VAL2')
在 Spring 启动应用程序中,它由MyType.class enum
表示
我正在尝试使用DatabasClient
运行一个简单的查询
client.exectute("select * from table where type = :type")...
作为错误,我得到:
ceptionFactory$PostgresqlBadGrammarException: operator does not exist: type = character varying
将类型转换为my_type
不起作用(CAST 和 ::)
我已经为MyType.class
注册了一个特定的编解码器,该编解码器有效 - 无条件查询所有内容适用于相关@ReadingConverter
Spring Data R2DBC和 R2DBC Postgres 都不能将枚举类型映射到 Postgres 枚举类型。
如果在 SQL 语句中检索时正确转换绑定值/列值,则仍然可以使用 Postgres 枚举类型表示为字符串。
例:
client.exectute("select type::text from table where type = :type::my_type")