postgresql - Postgres Crosstab query - "duplicate category" error where 2 values have the first 62 characters in common -


i'm newbie working on postgres 9.5 (dynamic) crosstab query, has been working fine in general, i've come peculiar issue large identical category names , hope there's easy solution/explanation.

requires tablefunc:

create extension if not exists tablefunc; 

schema:

create table temp_table (id integer, name text, data text); insert temp_table values (1, 'thissentenceisexactlysixtytwocharacterslongplusnumbersattheend',  'data1'); insert temp_table values (2, 'thissentenceisexactlysixtytwocharacterslongplusnumbersattheend1',  'data2'); 

query:

select * crosstab($$select id, name, data temp_table order 1,2$$ , $$select distinct name temp_table$$) ct (row integer, col_1 text,col_2 text); 

instead of result expect, get:

error: duplicate category name sql state: 42710

can please tell me what's going on here, , if there's simple fix? thanks!

i'm guessing has fact postgresql truncates identifiers (including column names , category names) 63 characters. seems there's off-by-one error somewhere in crosstab maybe. names need long? that's easiest fix. try increasing namedatalen , recompiling postgres.

https://www.postgresql.org/docs/current/static/sql-syntax-lexical.html#sql-syntax-identifiers