Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 9111F2E00F3 for ; Fri, 8 Feb 2008 09:18:01 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 46238-01 for ; Fri, 8 Feb 2008 09:17:58 -0400 (AST) Received: from ipmail01.adl6.internode.on.net (ipmail01.adl6.internode.on.net [203.16.214.146]) by postgresql.org (Postfix) with ESMTP id 9D82E2E2DAF for ; Fri, 8 Feb 2008 09:17:57 -0400 (AST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ah4FAFblq0fLevdH/2dsb2JhbAAsgS2qSg X-IronPort-AV: E=Sophos;i="4.25,321,1199626200"; d="scan'208";a="37846290" Received: from ppp247-71.static.internode.on.net (HELO DevBox.local) ([203.122.247.71]) by ipmail01.adl6.internode.on.net with ESMTP; 08 Feb 2008 23:47:53 +1030 Message-ID: <47AC567F.9020907@Sheeky.Biz> Date: Fri, 08 Feb 2008 23:47:51 +1030 From: Shane Ambler User-Agent: Thunderbird 2.0.0.6 (Macintosh/20070728) MIME-Version: 1.0 To: Shavonne Marietta Wijesinghe CC: pgsql-sql@postgresql.org Subject: Re: Serial not nulla References: <00a401c86a43$f88de120$3102a8c0@dream> In-Reply-To: <00a401c86a43$f88de120$3102a8c0@dream> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200802/61 X-Sequence-Number: 30152 Shavonne Marietta Wijesinghe wrote: > Hello > > I am working with a database that has a Index number defined as Serial NOT NULL > > I used this because, > 1. I want to make sure that when many users login at the same time the Index number won't be repeated. > 2. I don't have to increment it by programming (I use ASP) > > But now i have a situation that i need to index numbers. For Example i could have a structure like this > > INDEX1 - N_SHEET - TOT_SHEET > 1 - 1 - 1 > 2 - 1 - 3 > 2 - 2 - 3 > 2 - 3 - 3 > > N_SHEET and TOT_SHEET are filled by the user (via web) but i need to hold on to the INDEX. And while userA is filling the 3 row if userB loggs in i need to provide the INDEX1 with 3. > > Any idea?? > As well as using the "Serial NOT NULL" you have also defined this column as PRIMARY KEY (or a unique index) which is what is preventing the duplicates in that column. (A primary key is enforced with a unique index) From the sample shown you can use all three columns as the primary key with something similar to - ALTER TABLE my_user_sheets DROP CONSTRAINT my_user_sheets_pkey; ALTER TABLE my_user_sheets ADD PRIMARY KEY ("INDEX1", "N_SHEET", "TOT_SHEET"); (this implies that for each user they will have only one row for each combination of N_SHEET and TOT_SHEET) If you need to allow them to select the same 2 sheet numbers more than once then I would suggest you have an extra column for a primary key and redefine INDEX1 as the user_id. (or just add a user_id column and leave the INDEX1 as it is) It's not recommended but you could also have the table without a primary key allowing duplicate value combinations. This would prevent you updating a single row though. -- Shane Ambler pgSQL (at) Sheeky (dot) Biz Get Sheeky @ http://Sheeky.Biz