Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

fix(postgres): display reg types as text

onenewcode7a21e7e5f96e
diff --git a/crates/dbx-core/src/db/postgres.rs b/crates/dbx-core/src/db/postgres.rs
index 8647b9d12a..c880fbf9a3 100644
--- a/crates/dbx-core/src/db/postgres.rs
+++ b/crates/dbx-core/src/db/postgres.rs
@@ -587,8 +587,44 @@ fn pg_scalar_type_requires_text_protocol(oid: u32, col_type: PgColType) -> bool
Type::from_oid(oid).is_none() && !matches!(col_type, PgColType::Vector | PgColType::Geometry)
}
+/// PostgreSQL `reg*` types are OID-backed, but their useful representation is
+/// the catalog name returned by the text protocol (for example `regtype`
+/// returns `integer`). Decoding their binary payload as a generic value leaves
+/// the raw four-byte OID on the UI boundary, which is rendered as gibberish.
+fn pg_type_is_reg_type(pg_type: &Type) -> bool {
+ matches!(
+ pg_type.oid(),
+ oid if [
+ Type::REGPROC.oid(),
+ Type::REGPROCEDURE.oid(),
+ Type::REGOPER.oid(),
+ Type::REGOPERATOR.oid(),
+ Type::REGCLASS.oid(),
+ Type::REGTYPE.oid(),
+ Type::REGNAMESPACE.oid(),
+ Type::REGROLE.oid(),
+ Type::REGCOLLATION.oid(),
+ Type::REGCONFIG.oid(),
+ Type::REGDICTIONARY.oid(),
+ Type::REGPROC_ARRAY.oid(),
+ Type::REGPROCEDURE_ARRAY.oid(),
+ Type::REGOPER_ARRAY.oid(),
+ Type::REGOPERATOR_ARRAY.oid(),
+ Type::REGCLASS_ARRAY.oid(),
+ Type::REGTYPE_ARRAY.oid(),
+ Type::REGNAMESPACE_ARRAY.oid(),
+ Type::REGROLE_ARRAY.oid(),
+ Type::REGCOLLATION_ARRAY.oid(),
+ Type::REGCONFIG_ARRAY.oid(),
+ Type::REGDICTIONARY_ARRAY.oid(),
+ ]
+ .contains(&oid)
+ )
+}
+
fn pg_type_requires_text_protocol(pg_type: &Type, col_type: PgColType) -> bool {
- if pg_type.oid() == Type::RECORD.oid() || pg_type.oid() == Type::RECORD_ARRAY.oid() {
+ if pg_type.oid() == Type::RECORD.oid() || pg_type.oid() == Type::RECORD_ARRAY.oid() || pg_type_is_reg_type(pg_type)
+ {
return true;
}
@@ -6322,6 +6358,39 @@ mod tests {
assert!(pg_type_requires_text_protocol(&dynamic_record_array, PgColType::GenericArray));
}
+ #[test]
+ fn postgres_reg_types_use_text_protocol_for_catalog_names() {
+ // Binary reg* values are OIDs, while PostgreSQL's text output is the
+ // human-readable object/type name users expect to see in the grid.
+ for pg_type in [
+ Type::REGPROC,
+ Type::REGPROCEDURE,
+ Type::REGOPER,
+ Type::REGOPERATOR,
+ Type::REGCLASS,
+ Type::REGTYPE,
+ Type::REGNAMESPACE,
+ Type::REGROLE,
+ Type::REGCOLLATION,
+ Type::REGCONFIG,
+ Type::REGDICTIONARY,
+ Type::REGPROC_ARRAY,
+ Type::REGPROCEDURE_ARRAY,
+ Type::REGOPER_ARRAY,
+ Type::REGOPERATOR_ARRAY,
+ Type::REGCLASS_ARRAY,
+ Type::REGTYPE_ARRAY,
+ Type::REGNAMESPACE_ARRAY,
+ Type::REGROLE_ARRAY,
+ Type::REGCOLLATION_ARRAY,
+ Type::REGCONFIG_ARRAY,
+ Type::REGDICTIONARY_ARRAY,
+ ] {
+ assert!(pg_type_is_reg_type(&pg_type));
+ assert!(pg_type_requires_text_protocol(&pg_type, PgColType::Other));
+ }
+ }
+
#[test]
fn postgres_enum_keeps_binary_protocol() {
let enum_type = Type::new(