Search Postgresql Archives

crosstab doesn't work

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Dear all,

I installed postgresql 8.04 on a pentium box with freebsd 
5.4

# psql --version
psql (PostgreSQL) 8.0.4


In the db switch I have 
the following ct1 table

switch=# select * from ct1 order by 1,2;
 id | 
rowclass | rowid | attribute | value
----+----------+-------+-----------
+-------
  1 | group1   | test1 | att1      |     8
  2 | group1   | 
test1 | att2      |    15
  3 | group1   | test1 | att3      |    -1
  
4 | group1   | test1 | att4      |    12
  5 | group1   | test2 | 
att1      |    17
  6 | group1   | test2 | att2      |   456
  7 | 
group1   | test2 | att3      |     2
  8 | group1   | test2 | att4      
|   -12
  9 | group1   | test1 | att1      |    10
 10 | group1   | 
test2 | att2      |  -420
(10 righe)

crosstable seems to work (even 
though with wierd, wrong results for which I blame the repetition of 
some records and values) :

select * from crosstab('select rowid, 
attribute, value from ct1 where rowclass = ''group1'' order by 1,2;', 
2) as c(rowid text, att1 integer, att2 integer);
 rowid | att1 | att2
-------+------+------
 test1 |    8 |   10
 test2 |   17 | -420
(2 
righe)

If I aggregate

switch=# select rowid,attribute, sum(value) as 
val from ct1 group by rowid, attribute order by 1,2;
 rowid | attribute 
| val
-------+-----------+-----
 test1 | att1      |  18
 test1 | 
att2      |  15
 test1 | att3      |  -1
 test1 | att4      |  12
 
test2 | att1      |  17
 test2 | att2      |  36
 test2 | att3      |   
2
 test2 | att4      | -12
(8 righe)

crosstab doesn't seem to work 
anymore putting the above select into crosstab

switch=# select * from 
crosstab('select rowid,attribute, sum(value) as val from ct1 group by 
rowid, attribute order by 1,2;', 2) as c(rowid text, att1 integer, att2 
integer);
ERROR:  query-specified return row and actual function return 
row do not match

Please help I'm in badly need of the crosstab 
function.

Ciao
Vittorio



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux