pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
dynamic columns in a query
3+ messages / 3 participants
[nested] [flat]

* dynamic columns in a query
@ 2009-06-11 07:42 Jyoti Seth <jyotiseth2001@gmail.com>
  2009-06-11 07:53 ` Re: dynamic columns in a query A. Kretschmer <andreas.kretschmer@schollglas.com>
  2009-06-11 08:54 ` Re: dynamic columns in a query Pavel Stehule <pavel.stehule@gmail.com>
  0 siblings, 2 replies; 3+ messages in thread

From: Jyoti Seth @ 2009-06-11 07:42 UTC (permalink / raw)
  To: pgsql-sql

Hi All,

Is there any way in postgres to write a query to display the result in
matrix form. (where column names are dynamic)

For eg.


Employee Name	Client1	Client2	Client3	Client4
Emp1			100		102		90		23
Emp2			56		0		23		98
Emp3			34		45		76		0


Here Client1, Client2... are the values from the database.

Thanks,
Jyoti





^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: dynamic columns in a query
  2009-06-11 07:42 dynamic columns in a query Jyoti Seth <jyotiseth2001@gmail.com>
@ 2009-06-11 07:53 ` A. Kretschmer <andreas.kretschmer@schollglas.com>
  1 sibling, 0 replies; 3+ messages in thread

From: A. Kretschmer @ 2009-06-11 07:53 UTC (permalink / raw)
  To: pgsql-sql

In response to Jyoti Seth :
> Hi All,
> 
> Is there any way in postgres to write a query to display the result in
> matrix form. (where column names are dynamic)
> 
> For eg.
> 
> 
> Employee Name	Client1	Client2	Client3	Client4
> Emp1			100		102		90		23
> Emp2			56		0		23		98
> Emp3			34		45		76		0
> 
> 
> Here Client1, Client2... are the values from the database.

There is a contrib-modul, tablefunc. It contains a crosstab-function.
Maybe this can help you. Other solution: write a function in plpgsql and
build a string that contains your query, and EXECUTE that string.


Andreas
-- 
Andreas Kretschmer
Kontakt:  Heynitz: 035242/47150,   D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID:   0x3FFF606C, privat 0x7F4584DA   http://wwwkeys.de.pgp.net



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: dynamic columns in a query
  2009-06-11 07:42 dynamic columns in a query Jyoti Seth <jyotiseth2001@gmail.com>
@ 2009-06-11 08:54 ` Pavel Stehule <pavel.stehule@gmail.com>
  1 sibling, 0 replies; 3+ messages in thread

From: Pavel Stehule @ 2009-06-11 08:54 UTC (permalink / raw)
  To: Jyoti Seth <jyotiseth2001@gmail.com>; +Cc: pgsql-sql

Hello

2009/6/11 Jyoti Seth <jyotiseth2001@gmail.com>:
> Hi All,
>
> Is there any way in postgres to write a query to display the result in
> matrix form. (where column names are dynamic)
>

look on http://okbob.blogspot.com/2008/08/using-cursors-for-generating-cross.html

regards
Pavel Stehule

> For eg.
>
>
> Employee Name   Client1 Client2 Client3 Client4
> Emp1                    100             102             90              23
> Emp2                    56              0               23              98
> Emp3                    34              45              76              0
>
>
> Here Client1, Client2... are the values from the database.
>
> Thanks,
> Jyoti
>
>
>
> --
> Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql
>


^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2009-06-11 08:54 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2009-06-11 07:42 dynamic columns in a query Jyoti Seth <jyotiseth2001@gmail.com>
2009-06-11 07:53 ` A. Kretschmer <andreas.kretschmer@schollglas.com>
2009-06-11 08:54 ` Pavel Stehule <pavel.stehule@gmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox