Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 8AB6C9FB287 for ; Sun, 15 Jul 2007 12:36:19 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 69183-10 for ; Sun, 15 Jul 2007 12:36:07 -0300 (ADT) X-Greylist: delayed 00:07:40.662298 by SQLgrey-1.7.5 Received: from mail.frii.com (phobos02.frii.com [216.17.128.162]) by postgresql.org (Postfix) with ESMTP id 6D7CF9FB235 for ; Sun, 15 Jul 2007 12:36:16 -0300 (ADT) Received: from kyoto.home (smcgraw.ppp.frii.com [216.17.133.158]) by mail.frii.com (FRII) with ESMTP id 58E2811B3F59 for ; Sun, 15 Jul 2007 09:28:26 -0600 (MDT) Received: from maxwell (maxwell.home [10.1.65.135]) by kyoto.home (Postfix) with SMTP id D4A032A6648 for ; Sun, 15 Jul 2007 09:28:25 -0600 (MDT) From: "Stuart McGraw" To: Subject: data dependent sequences? Date: Sun, 15 Jul 2007 09:28:26 -0600 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="shift_jis" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.6604 (9.0.2911.0) Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1896 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.16 tagged_above=0 required=5 tests=AWL=0.159, BAYES_50=0.001 X-Spam-Level: X-Archive-Number: 200707/88 X-Sequence-Number: 28823 Advice requested :-) I have a table like: CREATE TABLE items ( id INT, typ INT ... PRIMAY KEY (seq,typ)); I would like 'id' to be like a SERIAL except that I want independent sequences for each value of 'typ'. So if 'items' is: id typ ----+----- 1 'a' 2 'a' 3 'a' 1 'b' then doing: INSERT items(typ) VALUES('a'); INSERT items(typ) VALUES('b'); will result in: id typ ----+----- 1 'a' 2 'a' 3 'a' 1 'b' 4 'a' 2 'b' Because there can be dozens of values of 'typ' and new ones added not infrequently, creating a postgresql sequence for each seems awkward. Are there other ways I could accomplish this?