Re: Subquery for column names of tablefunc crosstab queries

From: markw <mark(at)dimensionaledge(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Subquery for column names of tablefunc crosstab queries
Date: 2011-02-07 12:54:48
Message-ID: 1297083288892-3374199.post@n5.nabble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


Thanks Joe

I'm very much learning as I go.

I've followed your example from top to bottom - your sample code works -
however its not clear to me how to execute the generate_crosstab_sql
function to produce the results in one single step.

I've tried this:

CREATE OR REPLACE VIEW mycrosstabresults AS select * FROM (SELECT
generate_crosstab_sql('mytable',
'rowid',
'text',
'rowdt::date',
'temperature',
'int',
'1 = 1')) as crosstabresults;

but this simply populates the view with the string below, not the actual
crosstab results.

SELECT * FROM crosstab ('SELECT rowid,rowdt::date,temperature FROM
mytable WHERE 1 = 1 ORDER BY
1,2','VALUES($v$2003-03-01$v$),($v$2003-03-02$v$),($v$2003-03-03$v$)')
AS (rowid
text,"2003-03-01" int,"2003-03-02" int,"2003-03-03" int)

Is it possible to incorporate and execute this string, all within my CREATE
OR REPLACE VIEW statement?

I would appreciate any help you can give.

Many thanks

--
View this message in context: http://postgresql.1045698.n5.nabble.com/Subquery-for-column-names-of-tablefunc-crosstab-queries-tp3351437p3374199.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message A B 2011-02-07 14:00:54 How to create index on only some of the rows
Previous Message rsmogura 2011-02-07 11:44:36 XML Encoding problem