From 7243f5eb06e25b58c3b5f48de971af53afeb0824 Mon Sep 17 00:00:00 2001 From: Anubis <46840787+lazyanubis@users.noreply.github.com> Date: Wed, 5 Aug 2026 15:29:33 +0800 Subject: [PATCH] fix(postgresql): keep enum queries on binary protocol --- crates/dbx-core/src/db/postgres.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/crates/dbx-core/src/db/postgres.rs b/crates/dbx-core/src/db/postgres.rs index 7de45fc74..aa74b64f6 100644 --- a/crates/dbx-core/src/db/postgres.rs +++ b/crates/dbx-core/src/db/postgres.rs @@ -476,6 +476,7 @@ fn pg_type_requires_text_protocol(pg_type: &Type, col_type: PgColType) -> bool { } match pg_type.kind() { + Kind::Enum(_) => false, Kind::Array(element_type) => element_type.oid() >= POSTGRES_FIRST_NORMAL_OBJECT_ID, Kind::Simple => pg_scalar_type_requires_text_protocol(pg_type.oid(), col_type), _ => pg_type.oid() >= POSTGRES_FIRST_NORMAL_OBJECT_ID, @@ -4804,6 +4805,21 @@ mod tests { assert!(pg_type_requires_text_protocol(&dynamic_record_array, PgColType::GenericArray)); } + #[test] + fn postgres_enum_keeps_binary_protocol() { + let enum_type = Type::new( + "withdraw_btc_status".to_string(), + 98_765, + Kind::Enum(vec!["pending".to_string(), "completed".to_string()]), + "risk".to_string(), + ); + let enum_array = + Type::new("_withdraw_btc_status".to_string(), 98_766, Kind::Array(enum_type.clone()), "risk".to_string()); + + assert!(!pg_type_requires_text_protocol(&enum_type, PgColType::Other)); + assert!(pg_type_requires_text_protocol(&enum_array, PgColType::GenericArray)); + } + #[test] fn postgres_builtin_or_supported_type_keeps_binary_protocol() { assert!(!pg_scalar_type_requires_text_protocol(POSTGRES_FIRST_NORMAL_OBJECT_ID - 1, PgColType::Other));