Re: PG Unpivot ?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: dfgpostgres <dfgpostgres3(at)gmail(dot)com>
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: PG Unpivot ?
Date: 2025-11-03 17:33:23
Message-ID: 337595.1762191203@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-general

dfgpostgres <dfgpostgres3(at)gmail(dot)com> 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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2025-11-03 18:07:50 Re: Enquiry about TDE with PgSQL
Previous Message dfgpostgres 2025-11-03 17:32:09 Re: PG Unpivot ?