pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedquery or design question
2+ messages / 2 participants
[nested] [flat]
* query or design question
@ 2003-10-20 10:58 Adam Witney <awitney@sghms.ac.uk>
0 siblings, 1 reply; 2+ messages in thread
From: Adam Witney @ 2003-10-20 10:58 UTC (permalink / raw)
To: pgsql-sql
Hi,
I have a table like so
CREATE TABLE imagene (
id int
bioassay_id int
gene_id text
s_row int
s_column int
s_meta_row int
s_meta_column int
sig_median numeric
bkg_median numeric
);
Rows are unique on (bioassay_id, gene_id, s_row, s_column, s_meta_row,
s_meta_column)
They are grouped like this (note, the counts will not always be the same)
cabbage=# select bioassay_id, count(*) from imagene group by bioassay_id;
bioassay_id | count
-------------+-------
106 | 10944
107 | 10944
And I need to generate an output like this......
bioassay_id=106 bioassay_id=107
---------------------- ----------------------
gene_id, sig_median, bkg_median, sig_median, bkg_median
I can do something like this
SELECT a.gene_id,
a.sig_median, a.bkg_median,
b.sig_median, b.bkg_median
FROM
imagene a,
imagene b
WHERE
a.s_meta_row = b.s_meta_row AND
a.s_meta_col = b.s_meta_col AND
a.s_row = b.s_row AND
a.s_column = b.s_column AND
a.bioassay_id = 106 AND
b.bioassay_id = 107;
But this is quite slow... And not generic as I may need to generate the
output for more than two bioassay_ids. Also I may need to do an outer join
to make sure I get all rows from both data sets?
I am not sure if a crosstab function will do this?
Any ideas of pointers would be greatly appreciated
Thanks
Adam
--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: query or design question
@ 2003-10-20 17:12 Richard Huxton <dev@archonet.com>
parent: Adam Witney <awitney@sghms.ac.uk>
0 siblings, 0 replies; 2+ messages in thread
From: Richard Huxton @ 2003-10-20 17:12 UTC (permalink / raw)
To: Adam Witney <awitney@sghms.ac.uk>; pgsql-sql
On Monday 20 October 2003 11:58, Adam Witney wrote:
> Hi,
>
> I have a table like so
>
> CREATE TABLE imagene (
> id int
> bioassay_id int
> gene_id text
> s_row int
> s_column int
> s_meta_row int
> s_meta_column int
> sig_median numeric
> bkg_median numeric
> );
> And I need to generate an output like this......
>
> bioassay_id=106 bioassay_id=107
> ---------------------- ----------------------
> gene_id, sig_median, bkg_median, sig_median, bkg_median
> I am not sure if a crosstab function will do this?
There are some examples in contrib/tablefunc that might well be useful for
you. You should also check out the "Set Returning Functions" article on
http://techdocs.postgresql.org/
If you find your requirements getting particularly complex, I'd be tempted to
do the hard work in the application.
--
Richard Huxton
Archonet Ltd
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2003-10-20 17:12 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-10-20 10:58 query or design question Adam Witney <awitney@sghms.ac.uk>
2003-10-20 17:12 ` Richard Huxton <dev@archonet.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