Received: from localhost.localdomain (postgresql.org [64.49.215.8]) by localhost (Postfix) with ESMTP id F3FBE476571 for ; Tue, 9 Jul 2002 09:59:09 -0400 (EDT) Mailbox-Line: From bruno@wolff.to Tue Jul 9 09:59:09 2002 Received: from wolff.to (wolff.to [66.92.219.49]) by postgresql.org (Postfix) with SMTP id 46D144773ED for ; Tue, 9 Jul 2002 08:13:09 -0400 (EDT) Received: (qmail 30301 invoked by uid 500); 9 Jul 2002 12:18:36 -0000 Date: Tue, 9 Jul 2002 07:18:36 -0500 From: Bruno Wolff III To: Joachim Trinkwitz Cc: pgsql-sql@postgresql.org Subject: Re: INSERT only under certain conditions (SELECT) Message-ID: <20020709121836.GA30146@wolff.to> Mail-Followup-To: Joachim Trinkwitz , pgsql-sql@postgresql.org References: <874rfb6mqe.fsf@wabe.germanistik.uni-bonn.de> <20020708124013.GA30022@wolff.to> <87y9cm1aor.fsf@waffel.germanistik.uni-bonn.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87y9cm1aor.fsf@waffel.germanistik.uni-bonn.de> User-Agent: Mutt/1.3.25i X-Spam-Status: No, hits=-5.3 required=5.0 tests=IN_REP_TO,X_NOT_PRESENT version=2.30 X-Spam-Level: X-Archive-Number: 200207/114 X-Sequence-Number: 8493 On Mon, Jul 08, 2002 at 17:49:56 +0200, Joachim Trinkwitz wrote: > > Now I want to allow a user with id 123 only to insert a row in T if he > doesn't choose values from L with same 'art' and 'semester' values -- > in the examples user 123 has already chosen a kvvnr from semester > 2002ws in category 'art', so he shouldn't be allowed to insert the > values of the second row in table L. In the database you enforce this using a unique index. The application needs to be able to handle failures when you try to insert a duplicate key. If you can't afford to have a transaction fail part way through, then anything that writes that table should do a table lock at the start of the transaction.