Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hIbOR-0007GC-OQ for pgsql-general@arkaria.postgresql.org; Mon, 22 Apr 2019 16:02:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hIbOQ-0001nz-EK for pgsql-general@arkaria.postgresql.org; Mon, 22 Apr 2019 16:02:06 +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_SHA1:256) (Exim 4.89) (envelope-from ) id 1hIbNe-0005Be-NF for pgsql-general@lists.postgresql.org; Mon, 22 Apr 2019 16:01:18 +0000 Received: from mout.gmx.net ([212.227.17.22]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hIbNc-00078i-Ey for pgsql-general@lists.postgresql.org; Mon, 22 Apr 2019 16:01:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1555948873; bh=nzHNI6/61H9fG0iYusFzRpLgY8gfeHopWtBjwhZtKGQ=; h=X-UI-Sender-Class:Subject:To:References:From:Date:In-Reply-To; b=Y2nCZ2lEtmZsX5LRB1Asv+RDb/v22kw3Jj+RHMGavcP/jbfRc39+EVzwi9PfnXJGH SwDLJIwQWdnENp4u5AGkw6uI63vjMVuIzLQyBrchhOtTb6no6fJr6syrza0ilRZ63M uPSa8KIqKdvBJu4kUowSXIM5/roVAUcqnZsMzc5Y= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [192.168.178.37] ([93.104.68.174]) by mail.gmx.com (mrgmx103 [212.227.17.168]) with ESMTPSA (Nemesis) id 0McUnM-1ha8EL1I00-00Hbh2 for ; Mon, 22 Apr 2019 18:01:13 +0200 Subject: Re: Is it possible to store the output of EXPLAIN into a table To: pgsql-general@lists.postgresql.org References: From: Thomas Kellerer Message-ID: <9378a90b-e03b-1477-e6b8-0efacd2613ad@gmx.net> Date: Mon, 22 Apr 2019 18:01:13 +0200 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.1.21) Gecko/20090302 Thunderbird/2.0.0.21 Mnenhy/0.7.5.666 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: de-DE Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:ad0C5xiABvFIKfYWhO3Avinr4VX+wiHgS1AAkqMUo+wZcGpDB0x DIUG62wft0DfE5pGBObivrvwIUmlbdoCQI2Hp1C6oiC+yowhs+oUErj4U4fLiFShdgbRtt8 YDHiGz+voKreOblydjcN0hNFyZuopC0nMOr/+rZLeyucu3Yjj+RSTrKuyruiVXFu5Pf9dh5 vfeY7u65bwuO/Dd1gHrpQ== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:G4iqMIzk3qI=:T0LKdeTUBeH4kHCwBkmbMM 3uoo8B1g+uWWfndHzqwMP3a88XSNRx+Mrdv6rbSvKj7FH76YZVMezKeiUnyCOjdxKegsmt3af tL1cS9GAvSDiYO4/nBMduLaVOlRNMD13K4p2ot8koks+sf2cHv1zFkeYqprU2q2PsTmh4xRgM X+Cn5OkCZICqTVJ/m+2xFZvntVmI1I/l0Ikm3K+V3qUuxr1iI/2T28w7RYek8IZvDL1qwPBRg LUS8o/96m2SAE6+d8U6jduq058Hy30ku1eBJDnedLLk+G08AHXZjiMftNaIMAF3rXCYYhooyQ 9ejO1m45P1TlbqmDfjguVqHrZ//ezuvgnf3gZlxkYzYL3QJqKdqDgkUy+6xNjw1q4Twsu3nDS cs4r091PX2KGJUJoeaRGJr0kCIUNtjSVg2PDsyeNCDcnCCy6ZdUww+pNK8zNzohthzCX1BFdi EJeXTjDw4OkstvuuwAOFG9Alk5xHPpbapOgZRkWcD52u89KhwpctWJjDNrbeucmmauLamS3ej lfaC/sqNHsDKc8okXTl5xCjr2roy0Z9gz+9qUkRYM++lHRDTRdRh4eb252E4SgHbm/lzieK/i 2fWZ/UijiOzgtjlo1KEylA3DbmNUYbvpuKQF2FqJtNETF0A0BoD4ug0w7mygY3ANrCR9liSns k09ujuYPeg+K+Rs+Mb5h4NXevQU55kdFc4mY//1S2z9/Naw13I9C/taRqe9ghRpmkibudtHkg P+Ah+FuFcVi2AVVA2mQBlDzC8rqAHcTGdqdYJYTTy+Ps3s+y8BftKtRG0jcbp0NuVc5GPb7ik OQ+XZufQzWeMmCXMBc8CrW2kzOwxv3UpUpgFNPz+wU3cYibHbma16d2ouwtlAynDcoyAn/fvP gT7CDKTjrcv4E62Tg+AKe0V7Fd1kYOFXbJBa9eJsyhUSLqeiJPgBAvdtwcfuXiLT0zkfD74Qg qrvizNrPGTg== List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Souvik Bhattacherjee schrieb am 22.04.2019 um 17:27: > Hi, > > I was just wondering if it is possible to store the output of EXPLAIN in= to a table. > > create temp table mytab as (select * from (explain select * from table1 = where attr =3D 5) t); > > > Unfortunately, the query above does not work. You can't do that directly. You need to write a function that wraps the ex= plain, and returns the plan as a result set. Something like: create or replace function show_plan(to_explain text) returns table (line_nr integer, line text) as $$ declare l_plan_line record; l_line integer; begin l_line :=3D 1; for l_plan_line in execute 'explain (analyze, verbose, format xml)'||t= o_explain loop return query select l_line, l_plan_line."QUERY PLAN"::text; l_line :=3D l_line + 1; end loop; end; $$ language plpgsql; The you can use: create temp table mytab as select * from show_plan('select * from table1 where attr =3D 5');