1

我已将自定义域声明tmoney

create domain tmoney as decimal (13,4);

然后我在表声明中使用它的数组,

create table test (
  id        int generated by default as identity primary key,
  volume    smallint[5] not null default '{0, 0, 0, 0, 0}',
  price     tmoney[5]   not null default '{0, 0, 0, 0, 0}'
);

insert into test(volume, price) 
values ('{1, 10, 50, 100, 250}', '{10, 9.75, 9.5, 9, 8.75}');

在 PostgreSQL 12 中没有解析异常,因为它似乎以前存在过(请参阅创建自定义域 postgres 数组),但是,每当我尝试检索作为 tmoney[] 插入的值时,都会发现 DBCException。请注意,smallint[] 不会发生此错误。

select * from test;

id|volume           |price                                        |
--|-----------------|---------------------------------------------|
 1|{1,10,50,100,250}|DBCException: Can't resolve data type _tmoney|

https://www.postgresql.org/docs/current/sql-createdomain.html上的文档仅指定

tdata_type – 域的基础数据类型。这可以包括数组说明符。

这与创建为的域一致

create domain tmoney as decimal (13,4)[];

create table test (
  id        int generated by default as identity primary key,
  volume    smallint[5] not null default '{0, 0, 0, 0, 0}',
  price     tmoney  not null default '{0, 0, 0, 0, 0}'
);

insert into test(volume, price) 
values ('{1, 10, 50, 100, 250}', '{10, 9.75, 9.5, 9, 8.75}');

select * from test;

id|volume           |price                   |
--|-----------------|------------------------|
 1|{1,10,50,100,250}|{10.0,9.75,9.5,9.0,8.75}|

但是,由于 PostgreSQL 12 解析器不阻止tmoney[5]在表声明中使用,我想知道是否有不同的语法允许我使用自定义域的第一个版本。

4

1 回答 1

2

v11 中引入了使用域数组。

您的 SQL 语句与psql.

您必须使用可能无法正确支持的其他客户端。考虑使用该软件提交错误报告或增强请求。

于 2020-08-26T12:37:02.587 回答