Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 5BD4E9FB1D4 for ; Sun, 15 Jul 2007 13:07:15 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 88058-05 for ; Sun, 15 Jul 2007 13:07:06 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.5 Received: from web54306.mail.re2.yahoo.com (web54306.mail.re2.yahoo.com [206.190.49.116]) by postgresql.org (Postfix) with SMTP id B06A29F9F0C for ; Sun, 15 Jul 2007 13:07:14 -0300 (ADT) Received: (qmail 51576 invoked by uid 60001); 15 Jul 2007 16:07:05 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:Date:From:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-ID; b=oS6mDQnqWG7xcBTSGPeRNEl0en+15lcRdEHxk7wezB1xDGflWRBtK5bsyPxj+LXJyX7g6ghH5RolUuPyV1ArsIRRIGBluWSTIqI0R8s0cVeMwgOwBIJO1iQcbRaLfjga0OInJM5GOTup88TjcA2Wh90yQjbRnI4sGqaEb0RkZeY=; X-YMail-OSG: 190p1z8VM1nMrdyhFDiHrPkI38uZgUmQrRZ56NAOwD3jDgNI4RROWcmZT539eeHpmA-- Received: from [75.41.74.118] by web54306.mail.re2.yahoo.com via HTTP; Sun, 15 Jul 2007 09:07:05 PDT Date: Sun, 15 Jul 2007 09:07:05 -0700 (PDT) From: chester c young Subject: Re: data dependent sequences? To: sql pgsql In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Message-ID: <609880.51564.qm@web54306.mail.re2.yahoo.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200707/90 X-Sequence-Number: 28825 > > CREATE TABLE items ( > id INT, > typ INT ... > PRIMAY KEY (seq,typ)); > > id typ > ----+----- > 1 'a' > 2 'a' > 3 'a' > 1 'b' > 4 'a' > 2 'b' > you will need to use pre insert trigger since you cannot use column references in default expression. you could use this same trigger to either: - create sequences as needed and apply the right one - with locking, lookup for last id of typ - with locking, keep another table of typ and nextval ____________________________________________________________________________________ Yahoo! oneSearch: Finally, mobile search that gives answers, not web links. http://mobile.yahoo.com/mobileweb/onesearch?refer=1ONXIC