From: | Vittorio <vdemart1(at)tin(dot)it> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | crosstab doesn't work |
Date: | 2005-11-25 14:09:06 |
Message-ID: | 5828817.1132927746885.JavaMail.root@pswm19.cp.tin.it |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
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
From | Date | Subject | |
---|---|---|---|
Next Message | John McCawley | 2005-11-25 14:16:34 | Re: tool for DB design |
Previous Message | Florian G. Pflug | 2005-11-25 13:34:45 | Strange VACUUM behaviour |