sql - psql 你如何从复合数组中选择

标签 sql postgresql select psql composite-types

CREATE TYPE complex AS (
start_time timestamp,
amount int,
);

给定一个变量

my_complexes complex[]

怎么像查询表一样查询呢?

SELECT amount FROM my_complexes;

给出“关系不存在”。

SELECT mc.amount FROM (SELECT my_complexes) mc;

给出“数量不存在”。

如果相关,my_complexes 将作为函数的参数传入。然后我想在该数组上进行选择。

最佳答案

你应该使用:

SELECT (your_column_from_table_ my_complexes).amount FROM my_complexes;

完整示例:

CREATE TYPE complex AS (
   start_time timestamp,
   amount int
);

CREATE TABLE my_complexes (
    clm complex
);

INSERT INTO my_complexes VALUES ((LOCALTIMESTAMP, 112));
SELECT (clm).amount FROM my_complexes;

关于sql - psql 你如何从复合数组中选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32130483/

相关文章:

sql - If 语句 VBA 访问的 bool 问题

django - 推送 Heroku PostgreSQL 数据库时出现错误 "write EPIPE"

java - hibernate @ManyToMany,错误: relation does not exists

sql - 在 SQL Server 中执行嵌套 case 语句逻辑的最佳方法

C++选择问题

sql - 查询 - 与分区子句中的条件求和?

mysql - 如何计算查询中的年龄?

sql - 表 "ap"中有一个名为 "session"的列,但无法从这部分查询中引用它

postgresql - Postgres Slow group by query with max

MySQL 选择里面的选择里面的选择