Search Postgresql Archives

Re: Crosstab Problems

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

 



On 10/18/07, Stefan Schwarzer <stefan.schwarzer@xxxxxxxxxxxx> wrote:
> But when re-doing the query now without the JOIN, it works (almost):
>
> SELECT
>     *
> FROM
>     crosstab(
>        'SELECT
>             id_country AS id,
>             year_start AS year,
>             value
>         FROM
>             agri_area AS d
>         WHERE
>             year_start = 2003 OR year_start = 2002 OR year_start =
> 2001 ORDER BY year_start ASC, id_country ASC;'
>         , 3)
> AS ct(id int2, y_2003 numeric, y_2002 numeric, y_2001 numeric)
>
> Now, the problem is that it lists three times the IDs, and only the
> first year column is filled with values. The other two year columns
> stay empty.

You missed this point in the docs:

Notes

  1. The sql result must be ordered by 1,2.
Change your order by to that and it works fine.

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

[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