2

I need to concat two columns firstname and lastname as name in a crosstab select, example:

select * from crosstab('SELECT concat(u.firstname," ",u.lastname)as name

But I get this error:

column  « » doesn't exist.

How can I do it?

Erwin Brandstetter
  • 605,456
  • 145
  • 1,078
  • 1,228
user2009265
  • 23
  • 1
  • 4
  • It depends on whether any `NULL` value can be involved and on your version of Postgres. [This recent `[crosstab]` answer deals with the same problem and may be of help.](http://stackoverflow.com/a/21146080/939860) – Erwin Brandstetter Mar 08 '14 at 00:39

2 Answers2

2

Replace double quote by simple quote like:

SELECT concat(u.firstname,' ',u.lastname)
Houari
  • 5,326
  • 3
  • 31
  • 54
  • Thank you I replaced it and gives error: sintax error in or near «',u.lastname) as name, if I run the query out of crosstab it is ok. – user2009265 Mar 07 '14 at 22:50
1

Try this:

select * from crosstab('SELECT  concat(u.firstname,'' '',u.lastname) as name')

I added a missing "close quote" at the end of your crosstab string, and I doubled-up the single quotes to escape them within that string.

Robert N
  • 1,156
  • 2
  • 14
  • 32