Re: Best approach for a "gap-less" sequence

From: Harald Fuchs <hf0731x(at)protecting(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Best approach for a "gap-less" sequence
Date: 2006-08-14 20:12:08
Message-ID: pubqqnf55z.fsf@srv.protecting.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

In article <20060814162836(dot)58963(dot)qmail(at)web31811(dot)mail(dot)mud(dot)yahoo(dot)com>,
Richard Broersma Jr <rabroersma(at)yahoo(dot)com> writes:

> I am curious, can you calculate something like this using only sql? Or you you need to employee a
> procedural language like plpsgql?

You could use something like

SELECT (SELECT count(*) FROM tbl t2 WHERE t2.id < t1.id), whatever
FROM tbl t1

but correlated subqueries are slow; thus incrementing the counter in
the application would be faster for huge reports.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Harald Fuchs 2006-08-14 20:19:44 Re: Best approach for a "gap-less" sequence
Previous Message Berend Tober 2006-08-14 20:08:07 Re: Best approach for a "gap-less" sequence