X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 902B29DCB8E for ; Sun, 12 Feb 2006 19:20:08 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 46134-09 for ; Sun, 12 Feb 2006 19:20:10 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sccrmhc12.comcast.net (sccrmhc12.comcast.net [63.240.77.82]) by postgresql.org (Postfix) with ESMTP id F015B9DCB80 for ; Sun, 12 Feb 2006 19:20:05 -0400 (AST) Received: from cfgod (c-69-137-84-227.hsd1.tn.comcast.net[69.137.84.227]) by comcast.net (sccrmhc12) with SMTP id <2006021223200001200sd7rke>; Sun, 12 Feb 2006 23:20:08 +0000 From: "Foster, Stephen" To: "'Stephan Szabo'" Cc: Subject: Re: Trigger/Sequence headache Date: Sun, 12 Feb 2006 17:25:20 -0600 Message-ID: <000f01c6302b$9be85760$2101a8c0@cfgod> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook, Build 10.0.2616 In-Reply-To: <20060212150559.S97294@megazone.bigpanda.com> Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1506 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=1.608 required=5 tests=[AWL=-0.711, DNS_FROM_RFC_POST=1.44, DNS_FROM_RFC_WHOIS=0.879] X-Spam-Score: 1.608 X-Spam-Level: * X-Archive-Number: 200602/130 X-Sequence-Number: 24140 That's what I thought was going to be the answer. I was just hoping I was making a mistake somehow. It's no big deal but I like things organized and hate giant holes. Ok, one more thing for one of the batch jobs. No problem I have a cleanup routine. Thanks for the help, Lee Foster/ -----Original Message----- From: Stephan Szabo [mailto:sszabo@megazone.bigpanda.com] Sent: Sunday, February 12, 2006 5:11 PM To: Foster, Stephen Cc: pgsql-sql@postgresql.org Subject: Re: [SQL] Trigger/Sequence headache On Sun, 12 Feb 2006, Foster, Stephen wrote: > This is going to be one of those stupid problems of mine. I have an > insert trigger setup to verify that duplicate or repeating information > isn't storage in the table. If trigger function finds the information > as a duplicate it returns a NULL and the information isn't added; that > works. The problem I'm having is that it is incrementing the sequence > counter even when the data isn't added. Is this something that I have > to live with or should I be returning something other than a NULL? The sequence is going to increment upon getting the value. However, I think, if instead of using a default, you got the next value in the trigger after you determined that it wasn't a duplicate and set the field, it wouldn't increment for this case. This changes some other behaviors a little (for example DEFAULT in updates as well), so you'd need to see whether it'd be acceptable. Of course, errors, rollbacks and deletes will still leave holes.