[英]Scan PostgresQl enum to Protobuf enum
我已經在表格中歸檔了枚舉。 當我在sqlx Get() 方法的幫助下執行 SELECT 查詢時,我得到:
sql:列索引 1 上的掃描錯誤,名稱“type”:將 driver.Value 類型字符串(“INDIVIDUAL”)轉換為 int32:語法無效
Postgres 表:
create type account_type as enum ('INDIVIDUAL', 'BUSINESS');
create table account (
id varchar not null primary key,
type account_type not null,
email varchar(254) not null unique
);
原型文件的一部分:
enum AccountType {
INDIVIDUAL = 0;
BUSINESS = 1;
}
message Account {
string id = 1;
AccountType type = 2;
string email = 3;
}
SQL查詢:
SELECT id, type, email
FROM account
WHERE email = $1
LIMIT 1
如何將 PostgresQL 枚舉掃描到 Protobuf 枚舉? 我必須實現自己的掃描儀還是有其他方法?
我不知道它是否有什么不同(因為我完全不知道 GO),但發布的錯誤表明它可能。 Postgres 枚舉排序由浮點 (enumsortorder) 控制,而不是 integer。
postgres=# \d pg_enum
Table "pg_catalog.pg_enum"
Column | Type | Collation | Nullable | Default
---------------+------+-----------+----------+---------
enumtypid | oid | | not null |
enumsortorder | real | | not null |
enumlabel | name | | not null |
Indexes:
"pg_enum_oid_index" UNIQUE, btree (oid)
"pg_enum_typid_label_index" UNIQUE, btree (enumtypid, enumlabel)
"pg_enum_typid_sortorder_index" UNIQUE, btree (enumtypid, enumsortorder)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.