Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kffkf-0002ys-Ui for pgsql-general@arkaria.postgresql.org; Thu, 19 Nov 2020 08:57:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kffke-0000Po-FK for pgsql-general@arkaria.postgresql.org; Thu, 19 Nov 2020 08:57:12 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kffke-0000Pg-5M for pgsql-general@lists.postgresql.org; Thu, 19 Nov 2020 08:57:12 +0000 Received: from mout.gmx.net ([212.227.17.22]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kffka-00023H-FK for pgsql-general@lists.postgresql.org; Thu, 19 Nov 2020 08:57:11 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1605776224; bh=Ue1hBqOf7PvyIJZNHBEbyy3qbaQ/1VS2yzbnKqVwROs=; h=X-UI-Sender-Class:Subject:To:References:From:Date:In-Reply-To; b=FkfsIzKSMOdNdYqibz2t8guzzddYfs9mglJm4OfYIbMQ2v9qfvuXbgkg/3rRfvnBV tn+z6BhEU39Sd8vXkQqvhqgCB4WFk5nAS7Vfg/px/z+I4teScnRoAlyzxwT8P4Ggt5 +kAMJkgy4/QdxlDf1kzrc6HmCNZCJ9ihHbt1iJCg= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [10.1.34.88] ([185.40.248.10]) by mail.gmx.com (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1N8GQy-1kB1sG31fM-014FFx for ; Thu, 19 Nov 2020 09:57:04 +0100 Subject: Re: Multiple result set to be returned in procedure/function To: pgsql-general@lists.postgresql.org References: From: Thomas Kellerer Message-ID: Date: Thu, 19 Nov 2020 09:57:03 +0100 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.23) Gecko/20090812 Thunderbird/2.0.0.23 Mnenhy/0.7.6.666 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: de-DE Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:XjOLg4fRnnW8s3KbDjgwlTiLjKKdlVGZeSdpfvSoKRBH1a7UDdk 63DvkVVHsXOm1kfu2XK6VrYUZBFcuDxlNUScmd93FYDJvkEAl2eLLWRzL6NkJkxh2UuWC0l X3TQOobh64WGTKH5NFXHp+g32oiEXfVnLVmLx3Rn793n8USZge6mfZ4DGjivMfD1FS49dZd 5U6QxV1fMKzGF8gSLywtQ== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:pEfHsprhrio=:rfs0nSXRIuL4CXu5i/XiRY vhAVg8xaFwZ3Z+Mo1JsT6ufZlv3j8Dv2tK6hO51QQ1qe9pxPoV0/sYhVvjdY/ULYCE94vkwAC 0vePPP+VzgDu4/mgQXZnLYbdyG6WhOh/FDCfAn2hdC8Fy2DiFcwfIfaKd2mpBD/iVrSGEWrk0 K9LDbMsq8gbif+nKWtTqz0uZxiZeUiNXji6n8yCCO/znfusal9M/AuZMZI/ZsU2p4R5d6in7L BIQbbVfkG8QieSKh6bl1lE1WxwZBx0k4M8dr+lkFh0heUMrcA9Ng8XEYrKA3vmaYCQqmsx+mk lG66kHv6KE34V1Gs93h7mxKCcnypscslSu00SlzmkJNc5paL7GeSXWmiqt8ewz50cra0avph2 6X/FHZnl+rxIO+qmS5/SFIwVgcJCq+GsIZdG36IzN1DrxQKjZbXubQtkWC9GQ7G4D3b4nwtKZ sXL5MfFu0+MPWIsoTC1kDl2pT6tZdpmOz/aytl1AD4nKG9DrC7a3AcDjUG6H6if4vXiLRgkJ1 10OF7c8RooedyM0af8iMfhLQBHz0lK4CWGWWwnDPnTYQq2orXcrg4XVt4RGYjdMTfMnZ/QI+N ETyfQpZjGj9NelzV/ypKW48aztt2Q8V2buSpPNQIZswZx2GQ9uojN50svZyBh4nf6DdV89ScR O6coef3pHARMr989ojv2kFDqk59r1+QKA27UDMV5BzNkU1F4vGpE2RZfu9wItZmLouikis90n iC9oB44nX4f8I2dp3cv6vQqduGR9VDVp+GIwlqirjANUkGFH4b/BMLCtV0qsXkpbRIBzgJQCC j6PSWcMuxJcgB9XxEpVwVLDpxyNn0fVZ5aRjKtXrL/Eqh4XJxE+zOgnxg2JlGBScruAgrnwaJ hdmdXVv6ImqKsw7YlAlA== List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Muthukumar.GK schrieb am 19.11.2020 um 09:27: > is it possible to return Multiple results set from procedure/function > on single execution. Please advise me on this. we are planning to > migrate things from sqlserver to postgresql where my existing sql > stored procs will return multiple result set. so we need achieve same > thing in postgresql. You can achieve something like that, but it's a bit cumbersome to consume/= use the results: create function get_results() returns setof refcursor as $$ declare c1 refcursor; c2 refcursor; begin open c1 for select * from (values (1,2,3), (4,5,6)) as t(a,b,c); return next c1; open c2 for select * from (values ('one'),('two'),('three'),('four'= )) as p(name); return next c2; end; $$ language plpgsql; You have to turn off autocommit in order to be able to consume the results= . In psql you would get a result with two "unnamed portals" that you need to= fetch manually arthur=3D> \set AUTOCOMMIT off arthur=3D> select * from get_results(); get_results -------------------- arthur=3D> fetch all in fetch all in ""; a | b | c ---+---+--- 1 | 2 | 3 4 | 5 | 6 (2 rows) arthur=3D> fetch all in fetch all in ""; name ------- one two three four (4 rows) Other SQL clients might make this a bit easier. How exactly you deal with that in your application depends on the programming language you use. I would recommend to take the opportunity of the migration project and refactor your code so that you don't need this. Thomas