X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org Received: from localhost (neptune.hub.org [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 6E474D1B46C for ; Wed, 17 Dec 2003 07:59:34 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 84908-05 for ; Wed, 17 Dec 2003 03:59:04 -0400 (AST) Received: from mercury.wardbrook.com (217.79.104.122.adsl.griffin.net.uk [217.79.104.122]) by svr1.postgresql.org (Postfix) with ESMTP id 42C12D1B470 for ; Wed, 17 Dec 2003 03:59:02 -0400 (AST) Received: from localhost (mercury.wardbrook.com [127.0.0.1]) by mercury.wardbrook.com (Postfix) with ESMTP id 80ED2532EB; Wed, 17 Dec 2003 07:57:29 +0000 (GMT) Received: by mercury.wardbrook.com (Postfix, from userid 505) id 74D5F532ED; Wed, 17 Dec 2003 07:57:27 +0000 (GMT) Received: from 192.168.1.219 (mercury.wardbrook.com [127.0.0.1]) by mercury.wardbrook.com (Postfix) with SMTP id 91E0C532EB; Wed, 17 Dec 2003 07:57:24 +0000 (GMT) Received: from 192.168.0.64 (SquirrelMail authenticated user johnsw) by mercury.wardbrook.com with HTTP; Wed, 17 Dec 2003 07:57:24 -0000 (GMT) Message-ID: <1294.192.168.0.64.1071647844.squirrel@mercury.wardbrook.com> In-Reply-To: <3FDFAD8F.5080404@digitalflex.net> References: <3FDFAD8F.5080404@digitalflex.net> Date: Wed, 17 Dec 2003 07:57:24 -0000 (GMT) Subject: Re: Sequence question. From: "John Sidney-Woollett" To: "Anthony Best" Cc: pgsql-general@postgresql.org Reply-To: johnsw@wardbrook.com User-Agent: SquirrelMail/1.4.2 [CVS] MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Priority: 3 Importance: Normal X-Virus-Scanned: by AMaViS 0.3.12 X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200312/932 X-Sequence-Number: 54325 How about using two tables; one to hold the keyword and its (last allocated) sequence value, and the second to store your data as below. create table Keyword ( keyword varchar(32), sequence integer, primary key(keyword) ) create table Data ( id serial, sequence int, keyword varchar(32), text text ) Add a trigger to the Data table for Insert so that it joins to the (parent) keyword table and increments the keyword.sequence value, and places that into the Data.sequence value. You will get 'holes' in the keyword sequencing when you delete data from the Data table. If that's a problem then you will need an alternative design. Hope that helps. John Sidney-Woollett Anthony Best said: > I'm working on an idea that uses sequences. > > I'm going to create a table like this: > > id serial, > sequence int, > keyword varchar(32), > text text > > for every keyword there will be a uniq sequence for it eg: > > id, sequence, keyword > 1, 1, foo, ver1 > 2, 1, bar, bar ver1 > 3, 2, foo, ver2 > 4, 2, bar, bar ver2 > etc... > > I could have one sequence for all keyword which would be 1,3, etc... I > would be prefer to have them in sequence. I'm sure someone has ran into > this before, any ideas? > > Anthony. > > > ---------------------------(end of broadcast)--------------------------- > TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org >