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 1eknI2-0005Yv-4r for pgsql-general@arkaria.postgresql.org; Sun, 11 Feb 2018 08:47:14 +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 1eknHz-0005jC-Pu for pgsql-general@arkaria.postgresql.org; Sun, 11 Feb 2018 08:47:11 +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 1eknHz-0005j3-Ij for pgsql-general@lists.postgresql.org; Sun, 11 Feb 2018 08:47:11 +0000 Received: from mail.i-mark.de ([188.138.104.222]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eknHt-0004Lx-90 for pgsql-general@lists.postgresql.org; Sun, 11 Feb 2018 08:47:08 +0000 Received: from [192.168.222.106] (p5B31311B.dip0.t-ipconnect.de [91.49.49.27]) by mail.i-mark.de (Postfix) with ESMTPSA id F3E2F1580717 for ; Sun, 11 Feb 2018 09:46:48 +0100 (CET) Authentication-Results: loft7616.startdedicated.de; spf=pass (sender IP is 91.49.49.27) smtp.mailfrom=andreas@a-kretschmer.de smtp.helo=[192.168.222.106] Received-SPF: pass (loft7616.startdedicated.de: connection is authenticated) Subject: Re: execute block like Firebird does To: pgsql-general@lists.postgresql.org References: <1518328644815-0.post@n3.nabble.com> From: Andreas Kretschmer Message-ID: Date: Sun, 11 Feb 2018 09:46:38 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; 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: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Am 11.02.2018 um 06:57 schrieb PegoraroF10: > 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 ? you can use a DO - block: https://www.postgresql.org/docs/current/static/sql-do.html Regards, Andreas -- 2ndQuadrant - The PostgreSQL Support Company. www.2ndQuadrant.com