无法在 postgres 中对存储以 0 开头的数值的 varchar 字段进行分区

问题描述 投票:0回答:1

我正在使用 Postgres 13.9

以下是表结构:-

create table t5
(
id varchar(3), --using id as varchar since I want to retain leading 0. 
fname varchar
)partition by range (id);

create table t5_a partition of t5 for values from (001) to (010);
create table t5_b partition of t5 for values from (010) to (020);
create table t5_c partition of t5 for values from (020) to (030);

如果我尝试在下面插入

insert into t5 values('007', 'Tom');

它抛出以下错误:-

Error: no partition of relation "t5" found for row
postgresql partitioning
1个回答
0
投票

我在范围中添加了单引号,现在可以插入数据了:-

create table t5_a partition of t5 for values from ('001') to ('010');
create table t5_b partition of t5 for values from ('010') to ('020');
create table t5_c partition of t5 for values from ('020') to ('030');

insert into t5 values('007', 'Tom');

但是,需要注意的一件事是,如果您尝试仅传递 7 而不是“007”来插入数据,则会抛出错误。

© www.soinside.com 2019 - 2024. All rights reserved.