Re: SQL Query Syntax help - Mailing list pgsql-admin

From Daniel Verite
Subject Re: SQL Query Syntax help
Date
Msg-id 753eae4f-21b8-4aac-8687-e9a2b345dac1@manitou-mail.org
Whole thread Raw
In response to SQL Query Syntax help  ("srikkanth" <srikkanth16081991@rediffmail.com>)
List pgsql-admin
    srikkanth wrote:

> Can you please help me in writing the syntax for the below mentioned

This looks like an UNPIVOT operation.

Here's a generic method that does this without having to specify the
columns individually, with the help of json functions:

SELECT ID, key, value FROM
  (SELECT ID, row_to_json(t.*) AS line FROM PivotTableName t) AS r
JOIN LATERAL json_each_text(r.line) on (key <> 'ID');


Best regards,
--
Daniel Vérité
PostgreSQL-powered mailer: http://www.manitou-mail.org
Twitter: @DanielVerite



pgsql-admin by date:

Previous
From: "srikkanth"
Date:
Subject: SQL Query Syntax help
Next
From: Geoff Winkless
Date:
Subject: Re: SQL Query Syntax help