X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 87AA15E46BF for ; Mon, 16 Aug 2004 23:49:18 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 55948-10 for ; Tue, 17 Aug 2004 02:49:13 +0000 (GMT) Received: from angel.lonelyplanet.com.au (mail.lonelyplanet.com.au [202.147.44.168]) by svr1.postgresql.org (Postfix) with ESMTP id 2707F5E3F15 for ; Mon, 16 Aug 2004 23:49:09 -0300 (ADT) Received: from shiva.au.lpint.net ([192.168.61.22]) by angel with InterScan Messaging Security Suite; Tue, 17 Aug 2004 12:36:20 +1000 Received: by shiva.au.lpint.net with Internet Mail Service (5.5.2656.59) id ; Tue, 17 Aug 2004 12:47:13 +1000 Message-ID: <82E30406384FFB44AFD1012BAB230B55037D0510@shiva.au.lpint.net> From: Theo Galanakis To: "'pgsql-sql@postgresql.org'" Subject: Re: CROSS-TAB query help? I have read it cant be done in on Date: Tue, 17 Aug 2004 12:47:12 +1000 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2656.59) Content-Type: multipart/alternative; boundary="----_=_NextPart_001_01C48404.7F6B2380" X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=1.2 tagged_above=0.0 required=5.0 tests=EXCUSE_16, HTML_30_40, HTML_MESSAGE, PLING_QUERY X-Spam-Level: * X-Archive-Number: 200408/153 X-Sequence-Number: 18650 This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. ------_=_NextPart_001_01C48404.7F6B2380 Content-Type: text/plain Thanks Rickard Max may not work as not all the data is numerical. However I will give the contrib/cross-tab a go! Theo -----Original Message----- From: Richard Huxton [mailto:dev@archonet.com] Sent: Monday, 16 August 2004 6:06 PM To: Theo Galanakis Cc: 'pgsql-sql@postgresql.org' Subject: Re: [SQL] CROSS-TAB query help? I have read it cant be done in one SQL, pro ve them wrong! Theo Galanakis wrote: > Does anyone know how to perform a cross-tab query in ONE SQL without > having to write a SP? The SQL at the end of this email attempts to > display the subquery result-set in a cross-tab format, it does not > group the content onto one row as it should in the sample below. SQL > is below if it makes any sense, however the sub-query returns data as > below. > > Examle: > > Name Value > ID 1 > Cola 10 > Colb 20 > Colc 30 > Cold 40 > Cole 50 > > I want to output as: > > ID, cola, colb, colb, cold, cole > 1 10 30 30 40 50 > Actual Output: > > content_object_id | xpos | ypos | text | textangle | texttype > | symbol | linktype > -------------------+------+------+-------------------+-----------+---- > -------------------+------+------+-------------------+-----------+---- > -------------------+------+------+-------------------+-----------+-- > 100473 | 93 | | | | > 100473 | | 77 | | | > 100473 | | | text1 | | Don't forget the provided crosstab functions (in contrib/). If you don't want that, you could aggregate your results: SELECT content_object_id, MAX(xpos), MAX(ypos), ... FROM ( ) AS raw GROUP BY content_object_id; -- Richard Huxton Archonet Ltd ______________________________________________________________________ This email, including attachments, is intended only for the addressee and may be confidential, privileged and subject to copyright. If you have received this email in error, please advise the sender and delete it. If you are not the intended recipient of this email, you must not use, copy or disclose its content to anyone. You must not copy or communicate to others content that is confidential or subject to copyright, unless you have the consent of the content owner. ------_=_NextPart_001_01C48404.7F6B2380 Content-Type: text/html Content-Transfer-Encoding: quoted-printable RE: [SQL] CROSS-TAB query help? I have read it cant be done in one S= QL, pro ve them wrong!

Thanks Rickard
Max may not work as not all the data is numerical. Howev= er I will give the contrib/cross-tab a go!

Theo
-----Original Message-----
From: Richard Huxton [mailto:dev@archonet.com]
Sent: Monday, 16 August 2004 6:06 PM
To: Theo Galanakis
Cc: 'pgsql-sql@postgresql.org'
Subject: Re: [SQL] CROSS-TAB query help? I have read it = cant be done in one SQL, pro ve them wrong!


Theo Galanakis wrote:
> Does anyone know how to perform a cross-tab query i= n ONE SQL without
> having to write a SP? The SQL at the end of this em= ail attempts to
> display the subquery result-set in a cross-tab form= at, it does not
> group the content onto one row as it should in the = sample below. SQL
> is below if it makes any sense, however the sub-que= ry returns data as
> below.
>
> Examle:
>
> Name  Value
> ID    1
> Cola  10
> Colb  20
> Colc  30
> Cold  40
> Cole  50
>
> I want to output as:
>
> ID, cola, colb, colb, cold, cole
> 1     10    = ;  30      30      4= 0      50

> Actual Output:
>
>  content_object_id | xpos | ypos |  =      text        | t= extangle |  texttype
> |     symbol   &= nbsp; | linktype
> -------------------+------+------+-----------------= --+-----------+----
> -------------------+------+------+-----------------= --+-----------+----
> -------------------+------+------+-----------------= --+-----------+--
>        &nbs= p;    100473 | 93   |     = ; |            =        |      &= nbsp;    |
>        &nbs= p;    100473 |      | 77  = ; |            =        |      &= nbsp;    |
>        &nbs= p;    100473 |      |  &n= bsp;   | text1        &nb= sp;   |         &nbs= p; |

Don't forget the provided crosstab functions (in contrib/= ). If you don't
want that, you could aggregate your results:

SELECT content_object_id, MAX(xpos), MAX(ypos), ...
FROM (
<your query here>
) AS raw
GROUP BY content_object_id;

--
   Richard Huxton
   Archonet Ltd

____________________= __________________________________________________
This email, including= attachments, is intended only for the addressee
and may be confidential= , privileged and subject to copyright. If you
have received this email = in error, please advise the sender and delete
it. If you are not the in= tended recipient of this email, you must not
use, copy or disclose its c= ontent to anyone. You must not copy or
communicate to others content t= hat is confidential or subject to
copyright, unless you have the consen= t of the content owner.
------_=_NextPart_001_01C48404.7F6B2380--