"Keyed" sequence?

From: Israel Brewster <israel(at)ravnalaska(dot)net>
To: "pgsql-general(at)postgresql(dot)org general" <pgsql-general(at)postgresql(dot)org>
Subject: "Keyed" sequence?
Date: 2016-04-28 18:30:20
Message-ID: 2926B083-33C9-4648-8635-BC293C70ED45@ravnalaska.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

This is probably crazy talk, but in Postgresql is there any way to have a "keyed" sequence? That is, I have a table with a list of departments. While *relatively* static, technically speaking this is a dynamic list - someone certainly could decide to add a department, or combine two departments into one new one, whatever. In any case, I would ideally like to have a sequence per department, but since the list is dynamic it's not as simple as creating 33 independent sequences and then having a lookup table somewhere, although I guess I could implement something of the sort with triggers.

Is there any elegant way of accomplishing this? Something like SELECT nextval('department_seq['ops'])?

-----------------------------------------------
Israel Brewster
Systems Analyst II
Ravn Alaska
5245 Airport Industrial Rd
Fairbanks, AK 99709
(907) 450-7293
-----------------------------------------------

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Vik Fearing 2016-04-28 18:39:19 Re: "Keyed" sequence?
Previous Message Steve Atkins 2016-04-28 18:00:16 Re: CREATE EXTENSION without superuser access