我可以使用postgreSQL函数返回多个表吗? [英] Can I return multiple tables using postgreSQL function?

查看:72
本文介绍了我可以使用postgreSQL函数返回多个表吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的,





我是PostgreSQL的新手。我想在PostgreSQL中使用函数返回多个表,就像在MSSQL存储过程中编写多个select语句一样。



有人能建议我怎么做吗?



感谢所有人...

Dear all,


I am a newbie to PostgreSQL. I want to return multiple tables using function in PostgreSQL just like writing multiple select statement in MSSQL stored procedure.

Can anyone suggest me how to do it please?

Thank u to all...

推荐答案

这不是PostgreSQL纯粹支持的(据我所知) ),如果它们返回相同的行类型,您可以得到结果。您可以通过UNION ALL或类似的函数来执行此操作 -

This is not purely supported by PostgreSQL (as far as I know), you can get results combined if they return the same row type. You can do that either through a UNION ALL or a function like following-
CREATE FUNCTION test()
  RETURNS SETOF first_table AS


func


BEGIN

RETURN QUERY
SELECT * FROM first_table;

RETURN QUERY
SELECT * FROM second_table; - 必须返回与first_table相同的行类型

END
BEGIN RETURN QUERY SELECT * FROM first_table; RETURN QUERY SELECT * FROM second_table; -- has to return same rowtype as first_table END



参考: http:// stackoverflow .com / a / 7748232 [ ^ ]



希望,它有帮助;)


Reference: http://stackoverflow.com/a/7748232[^]

hope, it helps ;)


这篇关于我可以使用postgreSQL函数返回多个表吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆