postgresql - 如何从 PL/pgSQL 函数中的 select 中获取请求的列?
问题描述
有什么方法可以获取 Postgres 函数中请求的列列表?举例说明:
create type a_type as (id int, val text, expensive int[]);
create function find_by_id(rid int) returns setof a_type as $$
declare
atyp a_type%rowtype;
begin
select id,val from a_table where id=rid into atyp.id,atyp.val;
select array(select int_column from another_table where foreign_id=rid) into atyp.expensive;
return next atyp;
end;
$$ language plpgsql;
int[]
这是用我们主表上的外键查询另一个表的查询填充返回类型的字段,当然用select [COLUMN LIST] from find_by_id(ID)
. 有什么方法可以[COLUMN LIST]
从函数内部访问吗?如果expensive
未在列列表中指定,那么我不需要进行第二次选择并填充一个只会在返回结果之前被 Postgres 丢弃的字段。
解决方案
推荐阅读
- kubernetes-helm - 如何在 job.yaml 文件中以 Helm 图表语法编写以下条件?
- postgresql - Postgresql - 对附加到 timescaledb 的简单选择语句的慢速运行查询
- sockets - Socket.IO Kubernetes
- azure - 将两个不同的子域映射到一个 Azure 应用服务计划(内部包含两个不同的应用服务)
- junit - PowerMockito 验证对不同类的两个方法的静态调用
- java - 无法反序列化超出 START_ARRAY 令牌的实例
- c# - 如何在stimulsoft报告中添加两个业务对象之间的关系
- flutter - 在 Futurebuilder 中用于空值的空值检查运算符
- redirect - 您可以在 Joomla 的重定向组件中的 URL 重定向中使用某种通配符吗?
- python-3.x - 如何从 callback_query 对象编辑内联键盘?