pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
crosstab help
6+ messages / 3 participants
[nested] [flat]

* crosstab help
@ 2012-02-24 08:11 John Fabiani <johnf@jfcomputer.com>
  2012-02-24 08:27 ` Re: crosstab help Andreas Gaab <A.Gaab@scanlab.de>
  0 siblings, 1 reply; 6+ messages in thread

From: John Fabiani @ 2012-02-24 08:11 UTC (permalink / raw)
  To: pgsql-sql

I have a simple table
item_number  week_of               planned_qoh
------------------  ------------------       ------------------
00005	        2012-02-05           30
00005	        2012-02-12           40
00005	        2012-02-19           50


where 
item_number text
week_of date
planned_qoh integer

I have a function that returns the table as above:

chromasun._chromasun_totals(now()::date)

I want to see

00005   2012-02-05   2012-02-12    2012-02-19
                    30                  40                 50

This is what I have tried (although, I have tired many others)

select * from crosstab('select item_number::text as row_name, 
to_char(week_of,''MM-DD-YY'') as bucket, planned_qoh::integer as buckvalue 
from xchromasun._chromasun_totals(now()::date)')
as ct(item_number text, week_of date,  planned_qoh integer)

I get 
ERROR:  return and sql tuple descriptions are incompatible

What am I doing wrong?

Johnf



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

* Re: crosstab help
  2012-02-24 08:11 crosstab help John Fabiani <johnf@jfcomputer.com>
@ 2012-02-24 08:27 ` Andreas Gaab <A.Gaab@scanlab.de>
  2012-02-24 08:39   ` Re: crosstab help John Fabiani <johnf@jfcomputer.com>
  0 siblings, 1 reply; 6+ messages in thread

From: Andreas Gaab @ 2012-02-24 08:27 UTC (permalink / raw)
  To: pgsql-sql

Hi,

the return type of the crosstab must be defined correctly, according to the number of expected columns.

Try following (untested):

select * from crosstab(
'select item_number::text as row_name, to_char(week_of,''MM-DD-YY'')::date as bucket, planned_qoh::integer as buckvalue from xchromasun._chromasun_totals(now()::date)')
as ct(item_number text, week_of_1 date, week_of_2 date, week_of_3 date)

Regards,
Andreas



-----Ursprüngliche Nachricht-----
Von: pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-owner@postgresql.org] Im Auftrag von John Fabiani
Gesendet: Freitag, 24. Februar 2012 09:11
An: pgsql-sql@postgresql.org
Betreff: [SQL] crosstab help

I have a simple table
item_number  week_of               planned_qoh
------------------  ------------------       ------------------
00005	        2012-02-05           30
00005	        2012-02-12           40
00005	        2012-02-19           50


where
item_number text
week_of date
planned_qoh integer

I have a function that returns the table as above:

chromasun._chromasun_totals(now()::date)

I want to see

00005   2012-02-05   2012-02-12    2012-02-19
                    30                  40                 50

This is what I have tried (although, I have tired many others)

select * from crosstab('select item_number::text as row_name,
to_char(week_of,''MM-DD-YY'') as bucket, planned_qoh::integer as buckvalue from xchromasun._chromasun_totals(now()::date)')
as ct(item_number text, week_of date,  planned_qoh integer)

I get
ERROR:  return and sql tuple descriptions are incompatible

What am I doing wrong?

Johnf

--
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] 6+ messages in thread

* Re: crosstab help
  2012-02-24 08:11 crosstab help John Fabiani <johnf@jfcomputer.com>
  2012-02-24 08:27 ` Re: crosstab help Andreas Gaab <A.Gaab@scanlab.de>
@ 2012-02-24 08:39   ` John Fabiani <johnf@jfcomputer.com>
  2012-02-24 08:48     ` Re: crosstab help Andreas Gaab <A.Gaab@scanlab.de>
  0 siblings, 1 reply; 6+ messages in thread

From: John Fabiani @ 2012-02-24 08:39 UTC (permalink / raw)
  To: pgsql-sql

That worked!  However, I need the actual date to be the column heading?   And 
of course the dates change depending on the date passed to the function:
xchromasun._chromasun_totals(now()::date)

So how do I get the actual dates as the column header?
johnf
On Friday, February 24, 2012 09:27:38 AM Andreas Gaab wrote:
> Hi,
> 
> the return type of the crosstab must be defined correctly, according to the
> number of expected columns.
> 
> Try following (untested):
> 
> select * from crosstab(
> 'select item_number::text as row_name, to_char(week_of,''MM-DD-YY'')::date
> as bucket, planned_qoh::integer as buckvalue from
> xchromasun._chromasun_totals(now()::date)') as ct(item_number text,
> week_of_1 date, week_of_2 date, week_of_3 date)
> 
> Regards,
> Andreas
> 
> 
> 
> -----Ursprüngliche Nachricht-----
> Von: pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-owner@postgresql.org]
> Im Auftrag von John Fabiani Gesendet: Freitag, 24. Februar 2012 09:11
> An: pgsql-sql@postgresql.org
> Betreff: [SQL] crosstab help
> 
> I have a simple table
> item_number  week_of               planned_qoh
> ------------------  ------------------       ------------------
> 00005	        2012-02-05           30
> 00005	        2012-02-12           40
> 00005	        2012-02-19           50
> 
> 
> where
> item_number text
> week_of date
> planned_qoh integer
> 
> I have a function that returns the table as above:
> 
> chromasun._chromasun_totals(now()::date)
> 
> I want to see
> 
> 00005   2012-02-05   2012-02-12    2012-02-19
>                     30                  40                 50
> 
> This is what I have tried (although, I have tired many others)
> 
> select * from crosstab('select item_number::text as row_name,
> to_char(week_of,''MM-DD-YY'') as bucket, planned_qoh::integer as buckvalue
> from xchromasun._chromasun_totals(now()::date)') as ct(item_number text,
> week_of date,  planned_qoh integer)
> 
> I get
> ERROR:  return and sql tuple descriptions are incompatible
> 
> What am I doing wrong?
> 
> Johnf
> 
> --
> 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] 6+ messages in thread

* Re: crosstab help
  2012-02-24 08:11 crosstab help John Fabiani <johnf@jfcomputer.com>
  2012-02-24 08:27 ` Re: crosstab help Andreas Gaab <A.Gaab@scanlab.de>
  2012-02-24 08:39   ` Re: crosstab help John Fabiani <johnf@jfcomputer.com>
@ 2012-02-24 08:48     ` Andreas Gaab <A.Gaab@scanlab.de>
  2012-02-24 08:56       ` Re: crosstab help John Fabiani <johnf@jfcomputer.com>
  0 siblings, 1 reply; 6+ messages in thread

From: Andreas Gaab @ 2012-02-24 08:48 UTC (permalink / raw)
  To: pgsql-sql

As far as I know you must define the numbers (and types) of columns and column headers individually for each query or define some custom function...

Andreas

-----Ursprüngliche Nachricht-----
Von: pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-owner@postgresql.org] Im Auftrag von John Fabiani
Gesendet: Freitag, 24. Februar 2012 09:39
An: pgsql-sql@postgresql.org
Betreff: Re: [SQL] crosstab help

That worked!  However, I need the actual date to be the column heading?   And 
of course the dates change depending on the date passed to the function:
xchromasun._chromasun_totals(now()::date)

So how do I get the actual dates as the column header?
johnf
On Friday, February 24, 2012 09:27:38 AM Andreas Gaab wrote:
> Hi,
> 
> the return type of the crosstab must be defined correctly, according 
> to the number of expected columns.
> 
> Try following (untested):
> 
> select * from crosstab(
> 'select item_number::text as row_name, 
> to_char(week_of,''MM-DD-YY'')::date
> as bucket, planned_qoh::integer as buckvalue from
> xchromasun._chromasun_totals(now()::date)') as ct(item_number text,
> week_of_1 date, week_of_2 date, week_of_3 date)
> 
> Regards,
> Andreas
> 
> 
> 
> -----Ursprüngliche Nachricht-----
> Von: pgsql-sql-owner@postgresql.org 
> [mailto:pgsql-sql-owner@postgresql.org]
> Im Auftrag von John Fabiani Gesendet: Freitag, 24. Februar 2012 09:11
> An: pgsql-sql@postgresql.org
> Betreff: [SQL] crosstab help
> 
> I have a simple table
> item_number  week_of               planned_qoh
> ------------------  ------------------       ------------------
> 00005	        2012-02-05           30
> 00005	        2012-02-12           40
> 00005	        2012-02-19           50
> 
> 
> where
> item_number text
> week_of date
> planned_qoh integer
> 
> I have a function that returns the table as above:
> 
> chromasun._chromasun_totals(now()::date)
> 
> I want to see
> 
> 00005   2012-02-05   2012-02-12    2012-02-19
>                     30                  40                 50
> 
> This is what I have tried (although, I have tired many others)
> 
> select * from crosstab('select item_number::text as row_name,
> to_char(week_of,''MM-DD-YY'') as bucket, planned_qoh::integer as 
> buckvalue from xchromasun._chromasun_totals(now()::date)') as 
> ct(item_number text, week_of date,  planned_qoh integer)
> 
> I get
> ERROR:  return and sql tuple descriptions are incompatible
> 
> What am I doing wrong?
> 
> Johnf
> 
> --
> Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make 
> changes to your subscription: 
> http://www.postgresql.org/mailpref/pgsql-sql

--
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] 6+ messages in thread

* Re: crosstab help
  2012-02-24 08:11 crosstab help John Fabiani <johnf@jfcomputer.com>
  2012-02-24 08:27 ` Re: crosstab help Andreas Gaab <A.Gaab@scanlab.de>
  2012-02-24 08:39   ` Re: crosstab help John Fabiani <johnf@jfcomputer.com>
  2012-02-24 08:48     ` Re: crosstab help Andreas Gaab <A.Gaab@scanlab.de>
@ 2012-02-24 08:56       ` John Fabiani <johnf@jfcomputer.com>
  2013-06-05 04:24         ` Re: crosstab help Jayadevan <maymala.jayadevan@gmail.com>
  0 siblings, 1 reply; 6+ messages in thread

From: John Fabiani @ 2012-02-24 08:56 UTC (permalink / raw)
  To: pgsql-sql

Thanks for the insight!
johnf
On Friday, February 24, 2012 09:48:03 AM Andreas Gaab wrote:
> As far as I know you must define the numbers (and types) of columns and
> column headers individually for each query or define some custom
> function...
> 
> Andreas
> 
> -----Ursprüngliche Nachricht-----
> Von: pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-owner@postgresql.org]
> Im Auftrag von John Fabiani Gesendet: Freitag, 24. Februar 2012 09:39
> An: pgsql-sql@postgresql.org
> Betreff: Re: [SQL] crosstab help
> 
> That worked!  However, I need the actual date to be the column heading?  
> And of course the dates change depending on the date passed to the
> function: xchromasun._chromasun_totals(now()::date)
> 
> So how do I get the actual dates as the column header?
> johnf
> 
> On Friday, February 24, 2012 09:27:38 AM Andreas Gaab wrote:
> > Hi,
> > 
> > the return type of the crosstab must be defined correctly, according
> > to the number of expected columns.
> > 
> > Try following (untested):
> > 
> > select * from crosstab(
> > 'select item_number::text as row_name,
> > to_char(week_of,''MM-DD-YY'')::date
> > as bucket, planned_qoh::integer as buckvalue from
> > xchromasun._chromasun_totals(now()::date)') as ct(item_number text,
> > week_of_1 date, week_of_2 date, week_of_3 date)
> > 
> > Regards,
> > Andreas
> > 
> > 
> > 
> > -----Ursprüngliche Nachricht-----
> > Von: pgsql-sql-owner@postgresql.org
> > [mailto:pgsql-sql-owner@postgresql.org]
> > Im Auftrag von John Fabiani Gesendet: Freitag, 24. Februar 2012 09:11
> > An: pgsql-sql@postgresql.org
> > Betreff: [SQL] crosstab help
> > 
> > I have a simple table
> > item_number  week_of               planned_qoh
> > ------------------  ------------------       ------------------
> > 00005	        2012-02-05           30
> > 00005	        2012-02-12           40
> > 00005	        2012-02-19           50
> > 
> > 
> > where
> > item_number text
> > week_of date
> > planned_qoh integer
> > 
> > I have a function that returns the table as above:
> > 
> > chromasun._chromasun_totals(now()::date)
> > 
> > I want to see
> > 
> > 00005   2012-02-05   2012-02-12    2012-02-19
> > 
> >                     30                  40          
> >                           50
> > 
> > This is what I have tried (although, I have tired many others)
> > 
> > select * from crosstab('select item_number::text as row_name,
> > to_char(week_of,''MM-DD-YY'') as bucket, planned_qoh::integer as
> > buckvalue from xchromasun._chromasun_totals(now()::date)') as
> > ct(item_number text, week_of date,  planned_qoh integer)
> > 
> > I get
> > ERROR:  return and sql tuple descriptions are incompatible
> > 
> > What am I doing wrong?
> > 
> > Johnf
> > 
> > --
> > Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make
> > changes to your subscription:
> > http://www.postgresql.org/mailpref/pgsql-sql
> 
> --
> 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] 6+ messages in thread

* Re: crosstab help
  2012-02-24 08:11 crosstab help John Fabiani <johnf@jfcomputer.com>
  2012-02-24 08:27 ` Re: crosstab help Andreas Gaab <A.Gaab@scanlab.de>
  2012-02-24 08:39   ` Re: crosstab help John Fabiani <johnf@jfcomputer.com>
  2012-02-24 08:48     ` Re: crosstab help Andreas Gaab <A.Gaab@scanlab.de>
  2012-02-24 08:56       ` Re: crosstab help John Fabiani <johnf@jfcomputer.com>
@ 2013-06-05 04:24         ` Jayadevan <maymala.jayadevan@gmail.com>
  0 siblings, 0 replies; 6+ messages in thread

From: Jayadevan @ 2013-06-05 04:24 UTC (permalink / raw)
  To: pgsql-sql

Hello all ,
I have a similar situation - an EAV table.
entity_attr_id  integer          
 entity_id       bigint           
 ent_attr_value  character varying
I am trying 
select * from crosstab('select entity_id::text as row_name,
entity_attr_id::bigint as entity_attr_id , ent_attr_value::text  as
ent_attr_value from org_entity_attr_value order by 1') as ct(                
row_name text,entity_attr_id bigint,ent_attr_value text )
and get an error - 
ERROR:  return and sql tuple descriptions are incompatible





--
View this message in context: http://postgresql.1045698.n5.nabble.com/crosstab-help-tp5511994p5757977.html
Sent from the PostgreSQL - sql mailing list archive at Nabble.com.


-- 
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] 6+ messages in thread


end of thread, other threads:[~2013-06-05 04:24 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2012-02-24 08:11 crosstab help John Fabiani <johnf@jfcomputer.com>
2012-02-24 08:27 ` Andreas Gaab <A.Gaab@scanlab.de>
2012-02-24 08:39   ` John Fabiani <johnf@jfcomputer.com>
2012-02-24 08:48     ` Andreas Gaab <A.Gaab@scanlab.de>
2012-02-24 08:56       ` John Fabiani <johnf@jfcomputer.com>
2013-06-05 04:24         ` Jayadevan <maymala.jayadevan@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