pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Christopher Maier <maier@email.unc.edu>
To: pgsql-sql@postgresql.org
Subject: How can you generate a counter for ordered sets?
Date: Thu, 17 May 2007 09:19:48 -0400
Message-ID: <4E9181C4-E46A-4D0F-8A35-1EE1C64AC48E@email.unc.edu> (raw)

I am in the process of transitioning a bioinformatics database from  
one schema to another, and I have to do some "massaging" of the data  
in order to do it.

I have two tables, "gene" and "exon".  Exon has a many-to-one  
relationship with Gene.  The structure of the Gene table isn't  
important, but the Exon table looks like this:

CREATE TABLE exon(
	id SERIAL PRIMARY KEY,
	gene INTEGER REFERENCES gene(id),
	start INTEGER,
	stop INTEGER
);

Conceptually, all the exons for a given gene form a set, ordered by  
their "start" attribute.  I need to add a new integer column to the  
table to store a counter for each exon that indicates their position  
in this ordering.

Is there a straightforward way to populate this new position column?   
I've done an iterative solution in PL/pgSQL which works (slowly), but  
I was wondering if there was a more efficient way to do this kind of  
thing.

Thanks in advance,

Christopher Maier



view thread (2+ messages)  latest in thread

Message-ID: <4E9181C4-E46A-4D0F-8A35-1EE1C64AC48E@email.unc.edu>
Permalink:  ../4E9181C4-E46A-4D0F-8A35-1EE1C64AC48E@email.unc.edu/
Also on:    postgresql.org/message-id/4E9181C4-E46A-4D0F-8A35-1EE1C64AC48E@email.unc.edu

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: maier@email.unc.edu
  Subject: Re: How can you generate a counter for ordered sets?
  In-Reply-To: <4E9181C4-E46A-4D0F-8A35-1EE1C64AC48E@email.unc.edu>
  References: <4E9181C4-E46A-4D0F-8A35-1EE1C64AC48E@email.unc.edu>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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