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

[SQL] crosstab

2012-03-12 Thread 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 my table week_of date, item_number text, planned_demand integer. I have week_ofitem_number planned 2012-02-125200 2012-02-195

[SQL] crosstab maybe by case statement

2012-02-24 Thread John Fabiani
Hi Folks, I have one that I need your advise on how to construct. I have the need to create a series of dates starting from a Sunday - one week apart. (select ((date_trunc('week', '2012-02-12'::date)::date) +(i+6)) as week_date from generate_series(0,84,7) i) as foo that gives a table of sun

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
> Von: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql-ow...@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

Re: [SQL] crosstab help

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

[SQL] crosstab help

2012-02-24 Thread John Fabiani
I have a simple table item_number week_of planned_qoh -- -- -- 5 2012-02-05 30 5 2012-02-12 40 5 2012-02-19 50 where item_number text week_of date planned

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

[SQL] Crosstab Confusion

2010-02-01 Thread Adam Sherman
I'm really trying to understand how the tablefunc crosstab function works, to no avail. I have a table that looks like this: customer_id integer date timestamp with time zone amount numeric(10,4) There are rows in this table every-time a customer gets charged an amount, which is multiple times

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

[SQL] crosstab functions in postgres 8.1

2008-06-06 Thread Chris Preston
Hello, 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 mentioned that it might be because I am usin

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

[SQL] Crosstab limitation...

2007-11-30 Thread ronald tabada
Good day... I'm new in postgresql and I used PostgreSQL 8.2. I tried generating a query that can convert rows into columns. I was happy when I discovered the crosstab function. But when I tried producing reports with more than 17 columns it displayed the following error message: ERROR: invalid ret

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

[SQL] Crosstab question

2006-10-22 Thread Leendert Paul Diterwich
Dear list,   I recently discovered the crosstab function in postgresql. What I’m trying to accomplish is turn this:   Suppliernumber Productnumber Price 0  2  0.8 0  3  1.2 1  2  

Re: [despammed] [SQL] Crosstab function

2005-04-07 Thread Markus Schaber
Hi, Bandeng, bandeng schrieb: > I have install postgresql-contrib finally... i'm newbie in server. > I use freebsd 4.8, I saw in documentation it is said use tablefunc.sql > but in freebsd i found file tablefunc.so , it is already compiled. is > there suggestion to install tablefunc.so ? I think

Re: [despammed] [SQL] Crosstab function

2005-04-07 Thread bandeng
I have install postgresql-contrib finally... i'm newbie in server. I use freebsd 4.8, I saw in documentation it is said use tablefunc.sql but in freebsd i found file tablefunc.so , it is already compiled. is there suggestion to install tablefunc.so ? Thank you Ricky On Apr 6, 2005 3:32 PM, Andrea

Re: [despammed] [SQL] Crosstab function

2005-04-06 Thread Andreas Kretschmer
am 06.04.2005, um 13:55:35 +0700 mailte bandeng folgendes: > 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? apt-get install postgresql-contrib Regards, Andreas -- Andreas Kretschmer

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,

[SQL] Crosstab function

2005-04-05 Thread bandeng
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. Thanks Ricky -- Gutten Aben Sugeng Sonten, Jangane Kurang Santen bandeng -

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

[SQL] crosstab

2005-03-01 Thread Theo Galanakis
Title: crosstab Hi I have looked into the tablefunc / crosstab contrib for postgres and it appears like it can't perform what I need. The crosstab function converts this :     row_name    cat    value     --+---+---   row1  cat1    val1

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

[SQL] Crosstab question

2003-10-20 Thread Adam Witney
Hi, I am trying to figure out the use of crosstab(text sql, int N) The sql I have is cabbage=# select geneid, bioassay_id, sig_median from imagene order by 1,2; geneid | bioassay_id | sig_median -+-+ 16s rRNA (AP

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

[SQL] Crosstab-style query in pure SQL

2003-01-13 Thread dev
TIA all 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 output across the page l