Monday, 15 June 2015

Postgresql vertical to horizontal, one table -



Postgresql vertical to horizontal, one table -

i trying create little glossary in postgresql. until now, have table "vertical values"

general_id sing_id synonim language 1 1 yes en-gb 2 1 ja de-de 3 1 oui fr-fr 4 2 no en-gb 5 2 nein de-de 6 2 niet ru-ru select general_id, sing_id, synonim, language table1.base

but have this:

sing_id en_gb de_de fr_fr ru_ru ... 1 yes ja oui 2 no nein niet ...

would give me hint on how accomplish this?

you're talking 'pivoting'.

see post: pivoting in postgres

example post:

select * crosstab( 'select date, b.desc os, (random() * 10000 + 1)::int value generate_series((now() - ''100 days''::interval)::date, now()::date, ''1 day''::interval) a, (select unnest(array[''osx'', ''windows'', ''linux'']) desc) b order 1,2 ','select unnest(array[''osx'', ''windows'', ''linux''])' ) ct(date date, osx int, windows int, linux int);

postgresql

No comments:

Post a Comment