Re: [SQL] crosstab help

2013-06-04 Thread Jayadevan
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

Re: [SQL] crosstab

2012-03-12 Thread Pavel Stehule
2012/3/12 John Fabiani : > select * > from crosstab('select  item_number::text, week_of::date, planned_demand::text > from holding_table order by 1,2') > as ct(row_name text, week_of date, planned text) > > The above does not work.  What am I doing wrong? what it does? do you have tablefunc exten

Re: [SQL] crosstab

2012-03-12 Thread John Fabiani
select * from crosstab('select item_number::text, week_of::date, planned_demand::text from holding_table order by 1,2') as ct(row_name text, week_of date, planned text) The above does not work. What am I doing wrong? Johnf On Monday, March 12, 2012 06:01:21 PM Pavel Stehule wrote: > Hello > >

Re: [SQL] crosstab

2012-03-12 Thread Pavel Stehule
Hello maybe this article helps http://stackoverflow.com/questions/3002499/postgresql-crosstab-query there are more ways Regards Pavel Stehule 2012/3/12 John Fabiani : > Hi, > I don't know if it because I'm as sick as dog or I'm just a plain idiot - most > likely a little of both. > > Here is

Re: [SQL] crosstab help

2012-02-24 Thread John Fabiani
sprüngliche Nachricht- > Von: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql-ow...@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

Re: [SQL] crosstab help

2012-02-24 Thread Andreas Gaab
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

Re: [SQL] crosstab help

2012-02-24 Thread John Fabiani
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 An

Re: [SQL] crosstab help

2012-02-24 Thread Andreas Gaab
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

Re: [SQL] Crosstab Confusion

2010-02-01 Thread Lee Hachadoorian
On Mon, Feb 1, 2010 at 3:11 PM, Adam Sherman wrote: > Actually, the query I was running is: > > SELECT >cust_id as customer, >date_trunc(''day'', date) AS day, > SUM(billed_duration)/60.0::numeric(10,4) AS minutes > > billed_duration is an integer. Make sense? > > If billed_duration i

Re: [SQL] Crosstab Confusion

2010-02-01 Thread Adam Sherman
On 2010-02-01, at 14:22 , Lee Hachadoorian wrote: > The output column data type (day1, day2, etc.) is supposed to match the value > data type. I used numeric(10,4) because that's what your original post > specified, but the billed_duration column in your most recent post looks like > it might be

Re: [SQL] Crosstab Confusion

2010-02-01 Thread Lee Hachadoorian
The output column data type (day1, day2, etc.) is supposed to match the value data type. I used numeric(10,4) because that's what your original post specified, but the billed_duration column in your most recent post looks like it might be integer? (Or is it defined as numeric(10,4), but you never e

Re: [SQL] Crosstab Confusion

2010-02-01 Thread Adam Sherman
On 2010-02-01, at 11:34 , Lee Hachadoorian wrote: > You basically have three parts: > > 1) SELECT query in the form (row header, column header, cell value). In this > case it is an aggregate query so that you can sum the transactions over a > given day. > > 2) List of column headers. If you wa

Re: [SQL] Crosstab Confusion

2010-02-01 Thread Lee Hachadoorian
I'm flying blind here since I have nothing that looks like the structure you described to experiment on, but based on some crosstabs I have set up this should get you started. Explanatory notes follow. SELECT pivot.* FROM crosstab(' --row header, column header, cell value SELECT customer_i

Re: [SQL] crosstab functions in postgres 8.1

2008-06-06 Thread Tom Lane
"Chris Preston" <[EMAIL PROTECTED]> writes: > I am almost a newbie to postgres and only recently found out about one of > the greatest function crosstab in postgres. The problem is that I am using > 8.1 and when I run the function I am getting an error relating to > $libdir/tablefunc.. someone

Re: [SQL] Crosstab limitation...

2007-11-30 Thread Tom Lane
"ronald tabada" <[EMAIL PROTECTED]> writes: > ... when I tried > producing reports with more than 17 columns it displayed the following > error message: > ERROR: invalid return type > SQL state: 42601 > Detail: Query-specified return tuple has 39 columns but crosstab returns 17. Worksforme. Mayb

Re: [SQL] Crosstab question

2006-10-22 Thread Michael Fuhr
On Sun, Oct 22, 2006 at 01:57:09PM +0200, Leendert Paul Diterwich wrote: > The problem is that the data is being shifted when there is no > price for Supplier1 for product 3: > > Productnumber Supplier1 Supplier2 > 2 0.80.9 > 3

Re: [SQL] Crosstab function

2005-04-06 Thread Richard Huxton
bandeng wrote: hello guys, I want to use crosstab function but that function it doesnt exist. my version is 7.3 so how do i get the tablefunc.sql from postgre contrib? i saw in ver 8 win32 is checkable. Is it not in the contrib/ directory? Or did you install from a package of some sort (and if so,

Re: [SQL] crosstab

2005-03-01 Thread Josh Berkus
THeo, > I have tried using unions or subselects however the table is quite large > and it takes far too long to run. The most efficient way would be to create > a stored proc that uses a cursor to loop through the table transforming the > data into the new table structure. However I would apprecia

Re: [SQL] Crosstab question

2003-10-20 Thread Joe Conway
Adam Witney wrote: The missing values seemed to have been ignored and so the data is being shifted to the left and so put in the wrong columns. Am I using this function correctly? What is supposed to happen with missing values? Yeah, that's a limitation of the version of crosstab distributed with

Re: [SQL] Crosstab-style query in pure SQL

2003-01-13 Thread dev
> Richard, > >> I have a table containing milestones achieved for projects, marked as >> being in particular quarters. >> >> CREATE TABLE milestones ( >> proj_id int4, >> sortorder SERIAL, >> qtr int4, >> description varchar(200) >> ); >> >> Now I need the milestone de

Re: [SQL] Crosstab-style query in pure SQL

2003-01-13 Thread Josh Berkus
Richard, > I have a table containing milestones achieved for projects, marked as > being in particular quarters. > > CREATE TABLE milestones ( > proj_id int4, > sortorder SERIAL, > qtr int4, > description varchar(200) > ); > > Now I need the milestone descriptions o