//Creating Enumeration Classes
CREATE TYPE USER_ROLE AS ENUM ('MALE', 'FEMALE');
//Add conversion rules
CREATE CAST (VARCHAR AS USER_ROLE) WITH INOUT AS IMPLICIT;
//Create table, add fields of enumeration type
create table sys_user
(
row_id bigserial not null
constraint sys_user_pkey primary key,
create_time timestamp(6),
update_time timestamp(6),
del_flag smallint default 0 not null,
role USER_ROLE not null,
user_name varchar(200) not null
);
Because the conversion rule is added, you can directly use the varchar type string as the judgment condition query in pgadmin, but if you use mybatis to query the database, the error operator does not exist will be reported
select * from sys_user where del_flag = 0 and role = 'MALE'
Solution: convert varchar type to enumeration type and compare
Method 1
select * from sys_user where del_flag = 0 and role = cast(#{role} as user_role);
Method 2
select * from sys_user where del_flag = 0 and role = #{role}::user_role;
Read More:
- How to Solve postgres Errror: ERROR #42883 operator does not exist: smallint ~~ unknown
- How to Solve MYSQL ERROR: relation “table_name” does not exist
- postgresql-Database query problem-ERROR: column “t.domainid“ must appear in the GROUP BY clause or be used in an a
- [SQL ERROR] SQL Error: could not execute statement & query did not return a unique result: 2; nested excepti
- [Solved] ERROR 1054 (42S22): Unknown column ‘password‘ in ‘field list‘
- Error 1406 (22001) in MySQL: data too long for column (Fixed)
- [Solved] ERROR 1055 (42000): Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregate
- [Solved] public key is not available client side (option serverRsaPublicKeyFile not set)
- How to Fix MySQL error 1005: can’t create table (errno: 150)
- Caused by: com.ibatis.common.xml.NodeletException: Error parsing XML. Cause: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 281; The content of element type “sqlMapConfig” is incomplete
- [Solved] Pyodbc.ProgrammingError: No results. Previous SQL was not a query.
- [MySQL] mysql 5.5 and 5.6 timestamp default default value CURRENT_TIMESTAMP problem
- [Solved] Error: ER_HOST_NOT_PRIVILEGED: Host ‘x.x.x.x‘ is not allowed to connect to this MySQL server
- host ‘‘ is not allowed to connect to this mysql server Connect MYSQL Error
- [Solved] Sequelize DatabaseError: ER_WRONG_FIELD_WITH_GROUP: Expression #2 of SELECT list is not in GROUP
- How to Fix MySQL ERROR 1130 (HY000): Host ‘XXXX’ is not allowed to connect to this MySQL server
- Ubuntu ODBC MySQL 8 OPTION NOT Work [How to Solve]
- Remote connection to MySQL database error: is not allowed to connect to this MYSQL server solution
- [Solved]ERROR 1067 (42000): Invalid default value for ‘end_time‘ Mysql
- Caused by: java.sql.SQLTransientConnectionException: HikariPool-1 – Connection is not available, request timed out after 30005ms.