将PostgresQl枚举扫描到Protobuf枚举
我在表中有enum文件。在Get()方法的帮助下执行SELECT查询时,我得到: sql:列索引1上的扫描错误,名称为“type”:将driver.Value类型字符串(“单个”)转换为int32:无效语法 Postgres表:将PostgresQl枚举扫描到Protobuf枚举,sql,postgresql,enums,protocol-buffers,sqlx,Sql,Postgresql,Enums,Protocol Buffers,Sqlx,我在表中有enum文件。在Get()方法的帮助下执行SELECT查询时,我得到: sql:列索引1上的扫描错误,名称为“type”:将driver.Value类型字符串(“单个”)转换为int32:无效语法 Postgres表: create type account_type as enum ('INDIVIDUAL', 'BUSINESS'); create table account ( id varchar not null primary key, type accou
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;
}
SELECT id, type, email
FROM account
WHERE email = $1
LIMIT 1
原型文件的一部分:
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;
}
SELECT id, type, email
FROM account
WHERE email = $1
LIMIT 1
SQL查询:
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;
}
SELECT id, type, email
FROM account
WHERE email = $1
LIMIT 1
如何将PostgresQL枚举扫描到Protobuf枚举?我必须实现我自己的扫描仪还是有其他方法?我不知道这是否有什么不同(因为我完全不知道GO),但发布的错误表明可能会有不同。 Postgres枚举顺序由浮点(enumsortorder)控制,而不是整数
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)
我不知道它是否有什么不同(因为我完全不知道GO),但发布的错误表明它可能会有不同。 Postgres枚举顺序由浮点(enumsortorder)控制,而不是整数
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)