Kirk Wythers <wythe001@xxxxxxx> wrote: > Here is a simplified version of the query approach I am > attempting. > CREATE TABLE unstacked_table AS ( > SELECT > var1, > var2, > var3, > MAX ( > CASE > WHEN variable_name = 'unstack1' THEN > > VALUE > > END > ) AS unstack1, > MAX ( > CASE > WHEN variable_name = 'unstack2' THEN > > VALUE > > END > ) AS unstack2, > MAX ( > CASE > WHEN variable_name = 'unstack3' THEN > > VALUE > > END > ) AS unstack3, > MAX ( > CASE > WHEN variable_name = 'unstack4' THEN > > VALUE > > END > ) AS unstack4 > FROM > stacked_table > GROUP BY > variable1, > variable2, > variable3 > ) > ; This is still not making sense to me. Is VALUE intended to be a place-holder showing where you have a literal in the code? If so, what is the point of using MAX? Could you create a sample "stacked" table, insert about 10 rows, and show the SELECT which would give the "unstacked" form? -- Kevin Grittner EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company -- Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general