Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1vFyQs-004p2z-BO for pgsql-general@arkaria.postgresql.org; Mon, 03 Nov 2025 17:33:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1vFyQr-006q8t-8N for pgsql-general@arkaria.postgresql.org; Mon, 03 Nov 2025 17:33:28 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1vFyQq-006q7a-Tx for pgsql-general@lists.postgresql.org; Mon, 03 Nov 2025 17:33:27 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vFyQo-005Fjm-0i for pgsql-general@lists.postgresql.org; Mon, 03 Nov 2025 17:33:27 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 5A3HXNOb337596; Mon, 3 Nov 2025 12:33:23 -0500 From: Tom Lane To: dfgpostgres cc: pgsql-general@lists.postgresql.org Subject: Re: PG Unpivot ? In-reply-to: References: Comments: In-reply-to dfgpostgres message dated "Mon, 03 Nov 2025 12:18:55 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <337594.1762191203.1@sss.pgh.pa.us> Date: Mon, 03 Nov 2025 12:33:23 -0500 Message-ID: <337595.1762191203@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk dfgpostgres writes: > I want 9 records returned, each row with 3 cols, 1st col is the ctid, > second is the column name, third is the val. Perhaps psql's "expanded" mode is close enough? regression=# \x Expanded display is on. regression=# select * from unpivot; -[ RECORD 1 ]--- intcol | 1 floatcol | 1.1 strcol | one -[ RECORD 2 ]--- intcol | 2 floatcol | 2.2 strcol | two -[ RECORD 3 ]--- intcol | 3 floatcol | 3.3 strcol | three PS: I do not advise relying on ctid as a row identifier. Use a proper primary key. regards, tom lane