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 1iuEfh-0007cT-QI for pgsql-admin@arkaria.postgresql.org; Wed, 22 Jan 2020 11:59:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iuEei-0005LX-2r for pgsql-admin@arkaria.postgresql.org; Wed, 22 Jan 2020 11:58:44 +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 1iuEeh-0005LM-PQ; Wed, 22 Jan 2020 11:58:43 +0000 Received: from mail.verite.pro ([185.16.44.216]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1iuEea-0006uW-Tp; Wed, 22 Jan 2020 11:58:43 +0000 Received: from genius-map.net (verite.pro [195.154.189.246]) by mail.verite.pro (Postfix) with ESMTP id 2733D8C02B5; Wed, 22 Jan 2020 12:51:03 +0100 (CET) Received: by genius-map.net (Postfix, from userid 1001) id 6B72438A0EAA; Wed, 22 Jan 2020 12:58:34 +0100 (CET) Content-Type: text/plain; charset="iso-8859-15" Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: SQL Query Syntax help From: "Daniel Verite" To: "srikkanth" Cc: pgsql-admin@postgresql.org,pgsql-general@postgresql.org In-Reply-To: <20200122110045.14705.qmail@f4mail-235-235.rediffmail.com> Date: Wed, 22 Jan 2020 12:58:33 +0100 Message-Id: <753eae4f-21b8-4aac-8687-e9a2b345dac1@manitou-mail.org> X-Mailer: Manitou v1.7.3 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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, --=20 Daniel V=E9rit=E9 PostgreSQL-powered mailer: http://www.manitou-mail.org Twitter: @DanielVerite