PostgreSQL 选择复合元素数组
我有一个通过复合类型定义的表:
create type footype as (
a double precision,
b double precision
);
create table footable as (
x integer,
y footype []);
如何在表中包含的复合元素的单个字段上使用 select 语句?
预先感谢,
安东尼奥
I've got a table defined over a composite type:
create type footype as (
a double precision,
b double precision
);
create table footable as (
x integer,
y footype []);
How can I use a select statement on the single field of the composite elements contained in the table?
Thanks in advance,
Antonio
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
只是通常的 数组访问语法 后跟通常的 < a href="http://www.postgresql.org/docs/current/static/rowtypes.html#AEN7383" rel="noreferrer">复合类型访问语法。为了演示目的,进行一些设置:
然后:
您还可以访问 WHERE 子句中的复合类型:
Just the usual array access syntax followed by the usual composite type access syntax. So a bit of setup for demonstration purposes:
And then:
You can also access the composite type inside a WHERE clause:
首先,有一个错误,建表查询中的“as”一词是错误的。你应该这样写:
向表中插入数据:
通过字段获取数据:
First of all, there is one mistake, the word 'as' is wrong in the create table query. You should rather write this:
Insert data into the table:
Get the data by the fields:
我已经纠正了不起作用的解决方案,因为它在generate_subscripts()函数中存在错误。我更改了此函数中的列,因为它必须是数组类型列 (y),而不是原子类型列 (x):
I have corrected the solution that didn't work because it had a mistake in the generate_subscripts() function. I have changed the column in this function because it must be an array type column (y), not an atomic one (x):