Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 5A11E63271D for ; Fri, 25 Jun 2010 16:01:35 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 27163-01 for ; Fri, 25 Jun 2010 19:01:27 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from lo.gmane.org (lo.gmane.org [80.91.229.12]) by mail.postgresql.org (Postfix) with ESMTP id 0B5EC6324BE for ; Fri, 25 Jun 2010 16:01:27 -0300 (ADT) Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1OSE9V-0002bh-Ug for pgsql-sql@postgresql.org; Fri, 25 Jun 2010 21:01:25 +0200 Received: from e177122234.adsl.alicedsl.de ([85.177.122.234]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 25 Jun 2010 21:01:25 +0200 Received: from tim by e177122234.adsl.alicedsl.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 25 Jun 2010 21:01:25 +0200 X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: pgsql-sql@postgresql.org To: pgsql-sql@postgresql.org From: Tim Landscheidt Subject: Re: enforcing constraints across multiple tables Date: Fri, 25 Jun 2010 19:01:14 +0000 Organization: Lines: 21 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: e177122234.adsl.alicedsl.de Mail-Copies-To: never User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:v7itRPJ1YvK0Io0Wy5zZeXCYj7A= X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-5 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201006/93 X-Sequence-Number: 34284 Andrew Geery wrote: > [...] > My questions are: > (A) Is there a way to check (2) above using a constraint and not a trigger? > (B) Is there an easier way to solve this problem? Does the complicated > nature of the solution make the design poor? > (C) Should I not worry about this constraint at the DB level and just > enforce it at the application level? > [...] I don't know about (A) and (B), but (C) is the solution of choice in most complex cases. It's usually *much* easier to enforce than with constraints and triggers (you have to do it at application level anyway as well as you probably don't want to pass PostgreSQL's errors directly to the user) and your mind doesn't become twisted too much. I would schedule regular tests on the data set though to ensure that you no- tice problems early on. Tim