Skip to content
Advertisement

PostgreSQL says “return and sql tuple descriptions are incompatible”

I have the following data:

That I want to reorganize as:

Please note that the values in columns HBW, HBO and NHB are totals (sum).

Here is the script I am using to create the output:

When I run the script I get this error:

I am not sure what this means and how to correct the error. Can someone please let me know:

  1. What am I doing wrong in the script?
  2. Will my script produce the desired output?

Advertisement

Answer

This works for me on Postgres 9.3:

Produces the desired output.

Essential changes

  • the table alias (bold t)
  • the removed surplus column "value"
  • the correct data type for your data columns (double precision a.k.a. float8)

The rest is a matter of taste and style. I wouldn’t use value as column name though, since it is a reserved word in SQL.

Basics for crosstab() queries here:

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement