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

From: "Dawid Kuroczko" <qnex42(at)gmail(dot)com>
To: "Jorge Godoy" <jgodoy(at)gmail(dot)com>
Cc: "PostgreSQL General ML" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Best approach for a "gap-less" sequence
Date: 2006-08-16 20:53:25
Message-ID: 758d5e7f0608161353m50be2d09i88c39b8d8c417d9b@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 8/16/06, Dawid Kuroczko <qnex42(at)gmail(dot)com> wrote:
> -- then create a function to retrieve the values:
> CREATE FUNCTION gseq_nextval(t text) RETURNS integer AS $$
> DECLARE
> n integer;
> BEGIN
> SELECT INTO n gseq_value+1 FROM gapless_seq WHERE gseq_name = t
> FOR UPDATE;
> UPDATE gapless_seq SET gapless_value = n WHERE gseq_name = t;
> RETURN n;
> END;
> $$ STABLE LANGUAGE PLpgsql;
^^^^^^^^^^^
VOLATILE of course!

Regards,
Dawid

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2006-08-16 21:02:21 Re: COLLATE
Previous Message Dawid Kuroczko 2006-08-16 20:47:36 Re: Best approach for a "gap-less" sequence