Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1elwg7-0000ep-2I for pgsql-general@arkaria.postgresql.org; Wed, 14 Feb 2018 13:00:51 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1elwg5-0004Gf-1t for pgsql-general@arkaria.postgresql.org; Wed, 14 Feb 2018 13:00:49 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1elwg4-0004GV-Q8 for pgsql-general@lists.postgresql.org; Wed, 14 Feb 2018 13:00:48 +0000 Received: from server5.simfrete.com ([177.52.183.19]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1elwfr-0002Z7-Sd for pgsql-general@lists.postgresql.org; Wed, 14 Feb 2018 13:00:47 +0000 Received: from [192.168.10.30] (unknown [177.52.183.17]) by server5.simfrete.com (Postfix) with ESMTPSA id 26ADF241CF0 for ; Wed, 14 Feb 2018 11:03:52 -0200 (-02) Subject: Re: execute block like Firebird does To: pgsql-general@lists.postgresql.org References: <1518328644815-0.post@n3.nabble.com> From: Edson Carlos Ericksson Richter Message-ID: Date: Wed, 14 Feb 2018 11:00:28 -0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <1518328644815-0.post@n3.nabble.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: pt-BR List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Em 11/02/2018 03:57, PegoraroF10 escreveu: > We are migrating our databases from Firebird to PostGres. A useful feature > Firebird has is Execute Block. > What it does is just return a record set from that dynamic SQL, just like a > PostGres function, but without creating it. > It sound like ... > execute block returns(ID Integer, Name varchar(50), LastInvoice Date, ...) > as > begin > select bla, bla, bla into ...; > select bla, bla into ...; > suspend; > end > I know we could create a function but we have several hundred of these > blocks running, so ... it would be a huge work to do. > So, there is a way to run a dynamic sql which returns a set of records ? Can't you use "with ... select ..."? Like: with qry1 as (select bla, bla, bla from xyz), qry2 as (select bla, bla from ...) select * from qry1 union all select * from qry2 ? Regards, Edson -- > Sent from: http://www.postgresql-archive.org/PostgreSQL-general-f1843780.html > >