查询在pgsql存储过程中调用colpivot时没有结果数据

发布于 2025-02-09 17:11:40 字数 889 浏览 0 评论 0原文

我已经创建了一个程序来使用colpivot https://github.com/ 并将结果保存到PGSQL

create or replace procedure create_report_table()
language plpgsql
as $$
begin

drop table if exists reports;

select colpivot('_report',
'select
u.username,
c.shortname as course_short_name,
to_timestamp(cp.timecompleted)::date as completed
FROM mdl_course_completions AS cp
JOIN mdl_course AS c ON cp.course = c.id
JOIN mdl_user AS u ON cp.userid = u.id
WHERE c.enablecompletion = 1
ORDER BY u.username' ,array['username'], array['course_short_name'], '#.completed', null);

create table reports as (SELECT * FROM _report);

commit;
end; $$

COLPIVOT功能,drop Table,Delete表中的物理表中,删除表在隔离中确实很好。但是,当我按以上创建过程并调用执行过程时,这会引发错误 查询没有结果数据

我可以在任何方法中使用colpivot与我当前尝试的几个查询合作?

I have created a procedure to generate temp table using colpivot https://github.com/hnsl/colpivot
and saving the result into a physical table as below in PGSQL

create or replace procedure create_report_table()
language plpgsql
as $
begin

drop table if exists reports;

select colpivot('_report',
'select
u.username,
c.shortname as course_short_name,
to_timestamp(cp.timecompleted)::date as completed
FROM mdl_course_completions AS cp
JOIN mdl_course AS c ON cp.course = c.id
JOIN mdl_user AS u ON cp.userid = u.id
WHERE c.enablecompletion = 1
ORDER BY u.username' ,array['username'], array['course_short_name'], '#.completed', null);

create table reports as (SELECT * FROM _report);

commit;
end; $

colpivot function , drop table , delete table works really fine in isolation. but when I create the procedure as above, and call the procedure to execute, this throws an error Query has no result in destination data

Is there any way I can use colpivot in collaboration with several queries as I am currently trying ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不羁少年 2025-02-16 17:11:40

使用表演而不是选择。这将执行该语句,而无需将结果保留在某个地方。这就是

有时评估表达式或选择查询但丢弃结果很有用,例如调用具有
副作用,但没有有用的结果值。要在PL/PGSQL中执行此操作,请使用
表演语句

Use PERFORM instead of SELECT. That will execute the statement, without the need to keep the result somewhere. This is what the manual says:

Sometimes it is useful to evaluate an expression or SELECT query but discard the result, for example when calling a function that has
side-effects but no useful result value. To do this in PL/pgSQL, use
the PERFORM statement

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文